Files
supabase/apps/www/lib/changelog-entries-core.test.ts
Francesco SansalvadoreandClaude 00d12c305c Include Migration steps in changelog bodySection (#48496)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Feature / refactor

## What is the current behavior?

The changelog entry parser extracts `## Migration steps` as a separate
field (`migrationSteps`), and the `bodySection` stops before it. This
requires consumers to handle migration steps separately from the main
body content.

## What is the new behavior?

The `bodySection` now includes `## Migration steps` as part of the
rendered body content. The `migrationSteps` field has been removed from
the `ChangelogEntry` type. The `bodySection` extraction now stops at
internal-only planning sections (`## Rollout timeline`, `## Comms
timeline`) instead of at migration steps, allowing migration steps to be
included in the public-facing body.

## Additional context

- Updated `parseChangelogEntryFile` to extract `bodySection` through
migration steps, excluding only internal planning tables
- Updated the `ChangelogEntry` type documentation to clarify that
`bodySection` includes migration steps
- Added a test case verifying that migration steps are included in the
rendered body while internal sections are excluded
- This simplifies the API by consolidating public body content into a
single field

https://claude.ai/code/session_01X5ikaawVPZwMT5C2dWUyJY

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Improvements**
* Changelog entries now include all public content following the Body
section, including relevant subsections and rollout information.
* Migration guidance is included directly within the main changelog body
for a clearer reading experience.
* Internal notes, communications, and planning details remain excluded
from displayed changelog content.
* Unmatched internal markers now correctly hide all subsequent content
from public changelogs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-31 16:33:48 +02:00

208 lines
5.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
parseChangelogEntryFile,
PUBLIC_FRONTMATTER_KEYS,
toPublicFrontmatter,
} from './changelog-entries-core.mjs'
const ENTRY_WITH_INTERNAL = `---
title: Supabase Pipelines
change_type: new-feature
public: true
publish_date: 2026-01-01
affected_products:
- pipelines
internal:
escalation_teams:
- team-etl
notes: Do not ship this to the browser
reviewers:
- alice
---
# Summary
Pipelines are here.
# Body
Long form body.
`
describe('toPublicFrontmatter', () => {
it('keeps only allowlisted public keys', () => {
const publicFrontmatter = toPublicFrontmatter({
title: 'Hello',
change_type: 'new-feature',
internal: { escalation_teams: ['team-etl'] },
reviewers: ['alice'],
some_future_private_field: 'secret',
})
expect(publicFrontmatter).toEqual({ title: 'Hello', change_type: 'new-feature' })
for (const key of Object.keys(publicFrontmatter)) {
expect(PUBLIC_FRONTMATTER_KEYS).toContain(key)
}
})
it('omits keys whose value is undefined', () => {
expect(toPublicFrontmatter({ title: 'Hello', product_stage: undefined })).toEqual({
title: 'Hello',
})
})
it('normalizes Date-valued date fields to YYYY-MM-DD strings', () => {
const publicFrontmatter = toPublicFrontmatter({
title: 'Hello',
publish_date: new Date('2026-05-18T00:00:00.000Z'),
sunset_date: new Date('2026-08-05T00:00:00.000Z'),
}) as Record<string, unknown>
expect(publicFrontmatter.publish_date).toBe('2026-05-18')
expect(publicFrontmatter.sunset_date).toBe('2026-08-05')
expect(typeof publicFrontmatter.publish_date).toBe('string')
})
})
describe('parseChangelogEntryFile', () => {
it('never exposes the internal block on the parsed entry frontmatter', () => {
const entry = parseChangelogEntryFile('20260101-pipelines.md', ENTRY_WITH_INTERNAL)
// Untyped .mjs export, so `frontmatter` is inferred as {}.
const frontmatter = entry.frontmatter as Record<string, unknown>
expect(frontmatter.internal).toBeUndefined()
expect(frontmatter.reviewers).toBeUndefined()
expect(JSON.stringify(frontmatter)).not.toContain('team-etl')
expect(JSON.stringify(frontmatter)).not.toContain('escalation_teams')
expect(frontmatter.title).toBe('Supabase Pipelines')
expect(frontmatter.change_type).toBe('new-feature')
expect(frontmatter.public).toBe(true)
expect(frontmatter.affected_products).toEqual(['pipelines'])
})
it('always yields a string sortDate, even for an unquoted (Date-parsed) publish_date', () => {
const unquoted = parseChangelogEntryFile(
'20260722-unquoted.md',
`---\ntitle: Unquoted\nchange_type: improvement\npublic: true\npublish_date: 2026-05-18\n---\n\n# Body\n\nx\n`
)
expect(typeof unquoted.sortDate).toBe('string')
expect(unquoted.sortDate).toBe('2026-05-18')
const quoted = parseChangelogEntryFile(
'20260722-quoted.md',
`---\ntitle: Quoted\nchange_type: improvement\npublic: true\npublish_date: "2026-05-18"\n---\n\n# Body\n\nx\n`
)
expect(quoted.sortDate).toBe('2026-05-18')
// publish_date: null falls back to the filename date, also as a string.
const nullDate = parseChangelogEntryFile(
'20260722-null-date.md',
`---\ntitle: Null date\nchange_type: improvement\npublic: true\npublish_date: null\n---\n\n# Body\n\nx\n`
)
expect(nullDate.sortDate).toBe('2026-07-22')
})
it('includes everything under ## Body up to the internal block, and excludes internal content', () => {
const entry = parseChangelogEntryFile(
'20260714-breaking.md',
`---
title: Breaking change
change_type: breaking-change
public: true
publish_date: 2026-07-14
---
## Summary
Short summary.
## Body
## What changed
The thing changed.
## Migration steps
1. Do the thing.
2. Do the other thing.
## Rollout timeline
| Date | Milestone |
| ---- | --------- |
| 2026 | done |
<!-- internal -->
## Internal notes
secret
<!-- /internal -->
`
)
expect(entry.bodySection).toContain('## What changed')
expect(entry.bodySection).toContain('## Migration steps')
expect(entry.bodySection).toContain('Do the thing.')
expect(entry.bodySection).toContain('## Rollout timeline')
expect(entry.bodySection).not.toContain('## Summary')
expect(entry.bodySection).not.toContain('Short summary.')
expect(entry.bodySection).not.toContain('Internal notes')
expect(entry.bodySection).not.toContain('secret')
})
it('treats an unmatched opening <!-- internal --> marker as internal through end of file', () => {
const entry = parseChangelogEntryFile(
'20260714-unclosed-internal.md',
`---
title: Unclosed internal
change_type: improvement
public: true
publish_date: 2026-07-14
---
## Summary
Short summary.
## Body
Public body text.
<!-- internal -->
## Internal notes
super secret
## Support FAQ
more secret
`
)
expect(entry.bodySection).toContain('Public body text.')
expect(entry.bodySection).not.toContain('Internal notes')
expect(entry.bodySection).not.toContain('super secret')
expect(entry.bodySection).not.toContain('Support FAQ')
expect(entry.bodySection).not.toContain('more secret')
})
it('normalizes date frontmatter reaching detail-page props, even when unquoted', () => {
// `[slug].tsx` ships `entry.frontmatter` into props; a Date would break serialization.
const entry = parseChangelogEntryFile(
'20260722-unquoted-dates.md',
`---\ntitle: Unquoted dates\nchange_type: deprecation\npublic: true\npublish_date: 2026-05-18\nsunset_date: 2026-08-05\n---\n\n# Body\n\nx\n`
)
const frontmatter = entry.frontmatter as Record<string, unknown>
expect(frontmatter.publish_date).toBe('2026-05-18')
expect(frontmatter.sunset_date).toBe('2026-08-05')
expect(() => JSON.stringify(entry.frontmatter)).not.toThrow()
})
})