Repository navigation
feat(ci): publish spec-change manifests as workflow artifacts #265
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,14 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join, resolve } from "node:path"; | ||
| import { test } from "node:test"; | ||
| import { | ||
| firstParentFromRevList, | ||
| parseArgs, | ||
| parseTargetShas, | ||
| pullRequestMetadata, | ||
| writeManifests, | ||
| } from "../replay-spec-changes.mjs"; | ||
|
|
||
| const SHA_A = "a".repeat(40); | ||
|
|
@@ -65,47 +69,90 @@ test("pullRequestMetadata omits absent PR metadata", () => { | |
| ); | ||
| }); | ||
|
|
||
| test("parseArgs makes POST mode explicit, confirmed, and HTTPS-only", () => { | ||
| test("parseArgs makes writing explicit and confirmed, and rejects the removed push options", () => { | ||
| const base = [ | ||
| "node", | ||
| "replay", | ||
| "--shas", | ||
| SHA_A, | ||
| "--repository", | ||
| "workos/openapi-spec", | ||
| "--push", | ||
| ]; | ||
| assert.throws( | ||
| () => | ||
| parseArgs([ | ||
| ...base, | ||
| "--bot-url", | ||
| "https://sdk-automation-bot.workos.tools", | ||
| ]), | ||
| /Refusing to POST/, | ||
| () => parseArgs([...base, "--output-dir", "spec-changes"]), | ||
| /Refusing to write/, | ||
| ); | ||
| assert.throws( | ||
| () => | ||
| parseArgs([ | ||
| ...base, | ||
| "--bot-url", | ||
| "http://sdk-automation-bot.workos.tools", | ||
| "--confirm", | ||
| "REPLAY_SPEC_CHANGES", | ||
| "https://sdk-automation-bot.workos.tools", | ||
| ]), | ||
| /must use HTTPS/, | ||
| /Unknown option/, | ||
| ); | ||
| assert.throws(() => parseArgs([...base, "--push"]), /Unknown option/); | ||
|
|
||
| assert.equal(parseArgs(base).outputDir, ""); | ||
|
|
||
| const parsed = parseArgs([ | ||
| ...base, | ||
| "--bot-url", | ||
| "https://sdk-automation-bot.workos.tools", | ||
| "--output-dir", | ||
| "spec-changes", | ||
| "--confirm", | ||
| "REPLAY_SPEC_CHANGES", | ||
| ]); | ||
| assert.equal(parsed.push, true); | ||
| assert.equal( | ||
| parsed.endpoint.href, | ||
| "https://sdk-automation-bot.workos.tools/internal/spec-changes", | ||
| assert.equal(parsed.outputDir, resolve("spec-changes")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The updated tests check Prompt To Fix With AIThis is a comment left during a code review.
Path: scripts/__tests__/replay-spec-changes.spec.mjs
Line: 102
Comment:
**File writes lack test coverage**
The updated tests check `--output-dir` parsing but never exercise the new file-writing branch. Add tests using a temporary directory to check `<sha>.json` contents, skipping empty manifests, dry runs writing nothing, and a bad later target leaving no earlier files. These are the guarantees the artifact upload now depends on.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| }); | ||
|
|
||
| function rebuilt(targetSha, changedServices) { | ||
| const manifest = { | ||
| sha: targetSha, | ||
| parentSha: "b".repeat(40), | ||
| timestamp: "2026-06-22T00:00:00Z", | ||
| changedServices, | ||
| }; | ||
| return { targetSha, manifest, manifestText: `${JSON.stringify(manifest)}\n` }; | ||
| } | ||
|
|
||
| function scratchDir(t) { | ||
| const root = mkdtempSync(join(tmpdir(), "replay-write-")); | ||
| t.after(() => rmSync(root, { recursive: true, force: true })); | ||
| return join(root, "spec-changes"); | ||
| } | ||
|
|
||
| test("writeManifests writes one <sha>.json per target with changes and skips empty ones", (t) => { | ||
| const out = scratchDir(t); | ||
| const withChanges = rebuilt(SHA_A, [{ service: "SSO", hasBreaking: false }]); | ||
| const empty = rebuilt("c".repeat(40), []); | ||
|
|
||
| const written = writeManifests(out, [withChanges, empty]); | ||
|
|
||
| assert.deepEqual(written, [ | ||
| { targetSha: SHA_A, outputPath: join(out, `${SHA_A}.json`) }, | ||
| { targetSha: "c".repeat(40), outputPath: null }, | ||
| ]); | ||
| assert.deepEqual(readdirSync(out), [`${SHA_A}.json`]); | ||
| assert.equal(readFileSync(join(out, `${SHA_A}.json`), "utf8"), withChanges.manifestText); | ||
| }); | ||
|
|
||
| test("writeManifests validates every target before writing, so a bad later target leaves no files", (t) => { | ||
| const out = scratchDir(t); | ||
| const good = rebuilt(SHA_A, [{ service: "SSO", hasBreaking: false }]); | ||
|
|
||
| assert.throws( | ||
| () => writeManifests(out, [good, { targetSha: "main", manifest: {}, manifestText: "{}" }]), | ||
| /Invalid target SHA/, | ||
| ); | ||
| assert.throws( | ||
| () => writeManifests(out, [good, { ...good, targetSha: "d".repeat(40) }]), | ||
| /does not match target/, | ||
| ); | ||
| assert.throws(() => writeManifests(out, [good, { ...good, manifestText: "" }]), /Empty manifest/); | ||
| assert.throws( | ||
| () => writeManifests(out, [good, { ...good, manifest: { sha: good.targetSha } }]), | ||
| /no changedServices list/, | ||
| ); | ||
| assert.throws(() => writeManifests("", [good]), /output directory is required/); | ||
| assert.equal(existsSync(out), false); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.