-
Notifications
You must be signed in to change notification settings - Fork 5
fix(ci): redeploy the CDN after the release and gate on it catching up #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6a0b06
fix(ci): redeploy the CDN after the release and gate on it catching up
elkaix e7ad109
fix(tui): let only the dot carry background-task status
elkaix a13fce0
chore: add changeset for the background-task status colours
elkaix ec62c16
fix: address PR review findings
elkaix dc94f1d
docs: document the CDN manifest read helper
elkaix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@pythoughts/pythinker-code": patch | ||
| --- | ||
|
|
||
| Dim the wording on background task status lines so only the status dot is coloured. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
apps/pythinker-code/test/scripts/release/cdn-consistency.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| classifyCdnVersion, | ||
| compareRelease, | ||
| pollCdnUntilCaughtUp, | ||
| } from '../../../../../scripts/release/cdn-consistency.mjs'; | ||
|
|
||
| const URL = 'https://cdn.example/latest.json'; | ||
|
|
||
| /** Response stub shaped like the subset of `fetch` the poll actually reads. */ | ||
| function manifest(version: unknown, ok = true, status = 200) { | ||
| return { | ||
| ok, | ||
| status, | ||
| text: async () => JSON.stringify({ version }), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Fake clock and sleep: `sleep` advances the clock instead of waiting, so a | ||
| * ten-minute budget resolves instantly and the test asserts real elapsed logic. | ||
| */ | ||
| function fakeClock() { | ||
| let current = 0; | ||
| return { | ||
| now: () => current, | ||
| sleep: async (ms: number) => { | ||
| current += ms; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** Serve one scripted outcome per attempt. */ | ||
| function scriptedFetch(steps: readonly (() => unknown)[]) { | ||
| let index = 0; | ||
| return async () => { | ||
| const step = steps[Math.min(index, steps.length - 1)]; | ||
| index += 1; | ||
| return step?.(); | ||
| }; | ||
| } | ||
|
|
||
| describe('compareRelease', () => { | ||
| it('orders by major, then minor, then patch', () => { | ||
| const parse = (value: string) => /^(\d+)\.(\d+)\.(\d+)$/u.exec(value) as RegExpExecArray; | ||
| expect(compareRelease(parse('1.0.0'), parse('0.9.9'))).toBeGreaterThan(0); | ||
| expect(compareRelease(parse('0.13.0'), parse('0.12.0'))).toBeGreaterThan(0); | ||
| expect(compareRelease(parse('0.12.1'), parse('0.12.2'))).toBeLessThan(0); | ||
| expect(compareRelease(parse('0.12.0'), parse('0.12.0'))).toBe(0); | ||
| }); | ||
|
|
||
| it('separates identifiers that float arithmetic would round together', () => { | ||
| const parse = (value: string) => /^(\d+)\.(\d+)\.(\d+)$/u.exec(value) as RegExpExecArray; | ||
| // 9007199254740992 and 9007199254740993 are the same IEEE-754 double. | ||
| expect(compareRelease(parse('9007199254740993.0.0'), parse('9007199254740992.0.0'))).toBe(1); | ||
| expect(compareRelease(parse('0.9007199254740992.0'), parse('0.9007199254740993.0'))).toBe(-1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('classifyCdnVersion', () => { | ||
| it('reports an equal version as a match', () => { | ||
| expect(classifyCdnVersion('0.13.0', '0.13.0')).toBe('match'); | ||
| }); | ||
|
|
||
| it('reports an older CDN version as behind', () => { | ||
| expect(classifyCdnVersion('0.12.0', '0.13.0')).toBe('behind'); | ||
| expect(classifyCdnVersion('0.13.0', '1.0.0')).toBe('behind'); | ||
| }); | ||
|
|
||
| it('reports a newer CDN version as ahead', () => { | ||
| expect(classifyCdnVersion('0.14.0', '0.13.0')).toBe('ahead'); | ||
| }); | ||
|
|
||
| it('rejects anything that is not a stable release version', () => { | ||
| expect(classifyCdnVersion('not-a-version', '0.13.0')).toBe('invalid'); | ||
| expect(classifyCdnVersion('0.13.0-beta.1', '0.13.0')).toBe('invalid'); | ||
| expect(classifyCdnVersion('', '0.13.0')).toBe('invalid'); | ||
| expect(classifyCdnVersion(undefined, '0.13.0')).toBe('invalid'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('pollCdnUntilCaughtUp', () => { | ||
| const base = { url: URL, npmLatest: '0.13.0', budgetMs: 600_000, intervalMs: 15_000 }; | ||
|
|
||
| it('resolves on the first attempt when the CDN already matches', async () => { | ||
| const { now, sleep } = fakeClock(); | ||
| const result = await pollCdnUntilCaughtUp({ | ||
| ...base, | ||
| now, | ||
| sleep, | ||
| fetchImpl: scriptedFetch([() => manifest('0.13.0')]), | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ ok: true, reason: 'match', cdnVersion: '0.13.0', attempts: 1 }); | ||
| }); | ||
|
|
||
| it('keeps polling while the CDN is behind and succeeds once it catches up', async () => { | ||
| const { now, sleep } = fakeClock(); | ||
| const result = await pollCdnUntilCaughtUp({ | ||
| ...base, | ||
| now, | ||
| sleep, | ||
| fetchImpl: scriptedFetch([ | ||
| () => manifest('0.12.0'), | ||
| () => manifest('0.12.0'), | ||
| () => manifest('0.13.0'), | ||
| ]), | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ ok: true, reason: 'match', attempts: 3 }); | ||
| }); | ||
|
|
||
| it('treats an unreachable CDN as lag rather than a failure', async () => { | ||
| const { now, sleep } = fakeClock(); | ||
| const result = await pollCdnUntilCaughtUp({ | ||
| ...base, | ||
| now, | ||
| sleep, | ||
| fetchImpl: scriptedFetch([ | ||
| () => { | ||
| throw new Error('ECONNREFUSED'); | ||
| }, | ||
| () => manifest('0.13.0', false, 502), | ||
| () => ({ ok: true, status: 200, text: async () => 'not json' }), | ||
| () => manifest('0.13.0'), | ||
| ]), | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ ok: true, reason: 'match', attempts: 4 }); | ||
| }); | ||
|
|
||
| it('fails immediately when the CDN is ahead of npm', async () => { | ||
| const { now, sleep } = fakeClock(); | ||
| const result = await pollCdnUntilCaughtUp({ | ||
| ...base, | ||
| now, | ||
| sleep, | ||
| fetchImpl: scriptedFetch([() => manifest('0.14.0')]), | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ | ||
| ok: false, | ||
| reason: 'ahead', | ||
| cdnVersion: '0.14.0', | ||
| attempts: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('gives up with the last observed version once the budget expires', async () => { | ||
| const { now, sleep } = fakeClock(); | ||
| const result = await pollCdnUntilCaughtUp({ | ||
| ...base, | ||
| budgetMs: 45_000, | ||
| now, | ||
| sleep, | ||
| fetchImpl: scriptedFetch([() => manifest('0.12.0')]), | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ ok: false, reason: 'timeout', cdnVersion: '0.12.0' }); | ||
| expect(result.attempts).toBe(3); | ||
| }); | ||
|
|
||
| it('reports a null version when the CDN was never readable', async () => { | ||
| const { now, sleep } = fakeClock(); | ||
| const result = await pollCdnUntilCaughtUp({ | ||
| ...base, | ||
| budgetMs: 15_000, | ||
| now, | ||
| sleep, | ||
| fetchImpl: scriptedFetch([ | ||
| () => { | ||
| throw new Error('ENOTFOUND'); | ||
| }, | ||
| ]), | ||
| }); | ||
|
|
||
| expect(result).toMatchObject({ ok: false, reason: 'timeout', cdnVersion: null }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.