Skip to content

Commit 1d1ff5b

Browse files
authored
chore(sdk): generate the SDK fixture catalog from a script and add a generate-all umbrella (#10253)
1 parent 5cb1769 commit 1d1ff5b

5 files changed

Lines changed: 161 additions & 35 deletions

File tree

‎.agents/skills/ship/SKILL.md‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,14 @@ When the user runs `/ship`:
4747
- Run `/db-migrate` to review the migration for zero-downtime safety (expand/contract phasing, backward-compatibility with the deployed app version).
4848
- `(cd packages/db && bunx drizzle-kit generate && git status --porcelain ./migrations)` must print nothing (CI's schema/migration sync step).
4949
- `bun run check:migrations origin/staging` must pass (staging is the PR base). Do not silence a flagged statement with a `-- migration-safe:` annotation unless `/db-migrate` confirmed the old code no longer depends on it; otherwise split the destructive change into a later deploy.
50-
6. **Run pre-ship checks** from the repo root before staging. This has two phases: first **regenerate** every committed artifact so generated files never drift into a CI failure (this is what catches things like `agent-stream-docs` going stale after a `models.ts` edit), then run the **full audit suite** CI's `lint` job enforces. Both phases parallelize — but only across commands that write **disjoint** outputs — and a bare `wait` swallows child exit codes, so both phases below explicitly collect each job's status and abort ship if any failed.
50+
6. **Run pre-ship checks** from the repo root before staging. This has two phases: first **regenerate** every committed artifact so generated files never drift into a CI failure (this is what catches things like `agent-stream-docs` going stale after a `models.ts` edit), then run the **full audit suite** CI's `lint` job enforces. Both phases abort ship if any generator or audit fails: their runners (`scripts/generate-all.ts`, `scripts/run-audits.ts`) collect each job's exit code and exit non-zero, so never replace them with a backgrounded loop and a bare `wait`, which swallows child exit codes.
5151
52-
**Phase A — regenerate the always-in-repo committed artifacts (parallel), then let step 7 stage whatever changed.** Regenerate only the generators whose inputs live entirely in this repo and that any ordinary code change can drift — `generate:agent-stream-docs` (derives from the provider model registry), `generate:docs-manifest` (derives from docs page paths), `generate:tool-metadata` (derives from the tool registry), and `skills:sync` (derives from `.agents/skills/**`). They write disjoint outputs (`apps/docs/…/agent.mdx`, `apps/sim/lib/mothership/generated/docs-manifest.ts`, `apps/sim/tools/generated/*`, and `.claude/skills` links), so they parallelize safely, and each is idempotent (a no-op when already in sync):
52+
**Phase A — regenerate the always-in-repo committed artifacts, then let step 7 stage whatever changed.** Run the umbrella generator. It derives its list from package.json (every `generate:<x>` that has a matching `check:<x>`, plus `skills:sync`; see the header of `scripts/generate-all.ts`), so it covers every repo-local generator an ordinary code change can drift (a `models.ts` edit drifts `agent-stream-docs` and the SDK fixture catalog, a tool change drifts `tool-metadata`), runs them in the order their inputs require, and each is idempotent (a no-op when already in sync):
5353
```bash
54-
rm -f /tmp/ship-gen-results
55-
for g in generate:agent-stream-docs generate:docs-manifest generate:tool-metadata skills:sync; do
56-
( bun run "$g" >"/tmp/ship-gen-${g//:/-}.log" 2>&1; echo "$? $g" >>/tmp/ship-gen-results ) &
57-
done
58-
wait
59-
# any non-zero line is a FAILED generator — read /tmp/ship-gen-<name>.log and fix before shipping;
60-
# a silently-failed generate leaves a stale artifact that Phase B / CI then rejects. Keep the
61-
# `exit 1`: it is what makes the block's own status non-zero so a caller actually stops.
62-
if grep -vE '^0 ' /tmp/ship-gen-results; then echo "❌ generator(s) failed — do not ship"; exit 1; fi
54+
# A non-zero exit means a generator FAILED: the summary names it and its output is above. Fix it
55+
# before shipping; a silently-failed generate leaves a stale artifact that Phase B / CI then
56+
# rejects. Keep the `exit 1`: it makes the block's own status non-zero so a caller actually stops.
57+
bun run generate || { echo "❌ generator(s) failed — do not ship"; exit 1; }
6358
echo "✅ artifacts regenerated"
6459
```
6560
Then `git status --short` to see what regenerated — those files must be staged in step 7 alongside your own changes.

‎apps/sim/lib/workflows/code/real-catalog.test.ts‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* workflows against the types generated from the whole registry with the workspace's TypeScript 7
55
* compiler.
66
*/
7-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
7+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
88
import { tmpdir } from 'node:os'
99
import path from 'node:path'
1010
import { createBlock } from '@sim/testing/factories/block.factory'
@@ -32,9 +32,7 @@ import { afterAll, describe, expect, it, vi } from 'vitest'
3232
vi.unmock('@/blocks/registry')
3333
vi.unmock('@/tools/metadata-outputs')
3434

35-
import { projectBlockCatalog } from '@/lib/workflows/code/catalog/build'
3635
import { registryCatalog as catalog } from '@/lib/workflows/code/catalog/registry-catalog.test-helpers'
37-
import { registryTrigger } from '@/lib/workflows/code/catalog/registry-sources'
3836
import { generateRegistryCorpus } from '@/lib/workflows/code/corpus'
3937
import { createMaterializeHooks } from '@/lib/workflows/code/materialize-hooks'
4038
import {
@@ -44,7 +42,6 @@ import {
4442
} from '@/lib/workflows/code/sdk-typecheck.test-helpers'
4543
import { BUILTIN_SKILLS } from '@/lib/workflows/skills/builtin-skills'
4644
import { getBlockRegistry } from '@/blocks/registry'
47-
import { SDK_NAMES } from '@/blocks/sdk-names.generated'
4845

4946
const registryBlocks = Object.values(getBlockRegistry())
5047

@@ -82,26 +79,6 @@ const COOKBOOK_WORKSPACE: WorkspaceManifest = {
8279
}
8380

8481
describe('canonicalize and codegen over the real block catalog', () => {
85-
it('keeps the SDK fixture catalog equal to the real projection of its blocks', () => {
86-
const fixturePath = path.join(SDK_ROOT, 'test/fixtures/catalog.json')
87-
const fixture = JSON.parse(readFileSync(fixturePath, 'utf8')) as { blocks: object }
88-
const types = new Set(Object.keys(fixture.blocks))
89-
const projected = {
90-
...projectBlockCatalog({
91-
blocks: registryBlocks.filter((block) => types.has(block.type)),
92-
trigger: registryTrigger,
93-
sdkNames: SDK_NAMES,
94-
}),
95-
hash: 'fixture',
96-
}
97-
const text = `${JSON.stringify(projected, null, 2)}\n`
98-
if (process.env.UPDATE_SDK_FIXTURE_CATALOG === '1') writeFileSync(fixturePath, text)
99-
expect(
100-
JSON.parse(readFileSync(fixturePath, 'utf8')),
101-
'Regenerate with UPDATE_SDK_FIXTURE_CATALOG=1 bun run test lib/workflows/code/real-catalog.test.ts'
102-
).toEqual(JSON.parse(text))
103-
})
104-
10582
it("never freezes the host's timezone into the catalog as the schedule default", () => {
10683
const timezone = catalogBlock(catalog, 'schedule')?.subBlocks.find(
10784
(sub) => sub.id === 'timezone'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bun
2+
/**
3+
* Maintains `packages/workflow-sdk/test/fixtures/catalog.json`, the block catalog the SDK and CLI
4+
* tests compile against.
5+
*
6+
* The fixture is not hand-written: it is the real `projectBlockCatalog` projection of a subset of
7+
* registry blocks, so a test over it exercises the shapes production emits. The subset is the set
8+
* of block types already in the fixture; add a block by adding its type key to `blocks` and
9+
* regenerating. The hash is pinned to `'fixture'` so the file changes only when a projected block
10+
* does.
11+
*
12+
* Any change to a projected block, its tools' outputs, its SDK names, or a model list it reads
13+
* drifts this file, which is why `--check` runs in `check:audits` instead of leaving the drift for
14+
* a test shard to find.
15+
*
16+
* Usage:
17+
* bun run apps/sim/scripts/generate-sdk-fixture-catalog.ts # rewrite the fixture
18+
* bun run apps/sim/scripts/generate-sdk-fixture-catalog.ts --check # fail if it is stale
19+
*/
20+
import { readFile, writeFile } from 'node:fs/promises'
21+
import { dirname, resolve } from 'node:path'
22+
import { fileURLToPath } from 'node:url'
23+
import { projectBlockCatalog } from '@/lib/workflows/code/catalog/build'
24+
import { registryTrigger } from '@/lib/workflows/code/catalog/registry-sources'
25+
import { getBlockRegistry } from '@/blocks/registry'
26+
import { SDK_NAMES } from '@/blocks/sdk-names.generated'
27+
28+
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url))
29+
const FIXTURE_PATH = resolve(
30+
SCRIPT_DIR,
31+
'../../../packages/workflow-sdk/test/fixtures/catalog.json'
32+
)
33+
const FIXTURE_LABEL = 'packages/workflow-sdk/test/fixtures/catalog.json'
34+
35+
const checkOnly = process.argv.includes('--check')
36+
const current = await readFile(FIXTURE_PATH, 'utf8')
37+
const types = new Set(Object.keys((JSON.parse(current) as { blocks: object }).blocks))
38+
39+
const blocks = Object.values(getBlockRegistry()).filter((block) => types.has(block.type))
40+
const projected = {
41+
...projectBlockCatalog({ blocks, trigger: registryTrigger, sdkNames: SDK_NAMES }),
42+
hash: 'fixture',
43+
}
44+
const text = `${JSON.stringify(projected, null, 2)}\n`
45+
46+
if (checkOnly) {
47+
if (current !== text) {
48+
console.error(
49+
`${FIXTURE_LABEL} is stale: it no longer matches the registry projection of its ${types.size} blocks. Run \`bun run generate:sdk-fixture-catalog\` and commit the result.`
50+
)
51+
process.exit(1)
52+
}
53+
console.log(`${FIXTURE_LABEL} matches the registry projection of its ${types.size} blocks.`)
54+
} else if (current === text) {
55+
console.log(`${FIXTURE_LABEL} is already up to date (${types.size} blocks).`)
56+
} else {
57+
await writeFile(FIXTURE_PATH, text)
58+
console.log(`Regenerated ${FIXTURE_LABEL} (${types.size} blocks).`)
59+
}

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"check:sealed-columns": "bun run scripts/check-sealed-columns.ts",
8383
"check:schema-mock": "bun run scripts/generate-schema-mock.ts --check",
8484
"check:audits": "bun run scripts/run-audits.ts",
85+
"generate": "bun run scripts/generate-all.ts",
8586
"check:skills": "bun run scripts/sync-skills.ts --check",
8687
"check:guidance-refs": "bun run scripts/check-guidance-refs.ts",
8788
"check:desktop-bridge": "bun run scripts/check-desktop-bridge-contract.ts --check",
@@ -102,6 +103,8 @@
102103
"check:tool-metadata": "bun run scripts/sync-tool-metadata.ts --check",
103104
"generate:sdk-names": "bun run apps/sim/scripts/generate-sdk-names.ts",
104105
"check:sdk-names": "bun run apps/sim/scripts/generate-sdk-names.ts --check",
106+
"generate:sdk-fixture-catalog": "bun run apps/sim/scripts/generate-sdk-fixture-catalog.ts",
107+
"check:sdk-fixture-catalog": "bun run apps/sim/scripts/generate-sdk-fixture-catalog.ts --check",
105108
"check:sdk-names-frozen": "bun run scripts/check-sdk-names-frozen.ts",
106109
"generate:deployment-config": "bun run scripts/generate-deployment-config.ts",
107110
"check:deployment-config": "bun run scripts/generate-deployment-config.ts --check",

‎scripts/generate-all.ts‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bun
2+
/**
3+
* Runs every self-contained, repo-local generator, so a contributor (or `/ship`) can bring all
4+
* committed artifacts back in sync with one command: `bun run generate`.
5+
*
6+
* The list is derived from package.json the way `run-audits.ts` derives its audits, so a new
7+
* generator is picked up by default rather than added to a list here. A generator qualifies when
8+
* it has a matching audit: every `generate:<x>` that has a `check:<x>`, plus the older names in
9+
* {@link ALIASED_PAIRS}. That pairing is the repo's convention for "this artifact is a pure
10+
* function of the tree" (`check:audits` runs the check), so it is also what makes a generator safe
11+
* to run unprompted. Name a new generator `generate:<x>` / `check:<x>` and it runs here.
12+
*
13+
* Deliberately not run: the `<x>:generate` / `<x>:check` suffix pairs (`mship*`, `trace-*`,
14+
* `metrics`, `vfs`, `billing-protocol`, `images`, `library:covers`), which need the sibling
15+
* copilot repo, a Helm render, or a per-machine renderer (see `run-audits.ts`);
16+
* `generate:pi-model-catalog` under `apps/sim`, which reads an installed package; and
17+
* `scripts/generate-docs.ts`, whose broad integration-docs rewrite has no `generate:` script.
18+
*
19+
* Generators run one at a time, in package.json order, because they are not independent: some
20+
* read what an earlier one wrote. `generate:cli-docs` reads the operation table
21+
* `generate:cli-api` emits, `generate:docs-manifest` lists the pages `generate:cli-docs` writes,
22+
* and `generate:sdk-fixture-catalog` projects through `generate:tool-metadata` and
23+
* `generate:sdk-names` output. Keep a new pair below the generators it reads.
24+
*
25+
* Exits non-zero when any generator fails; the rest still run so one failure does not hide another.
26+
*
27+
* Usage:
28+
* bun run generate
29+
*/
30+
import path from 'node:path'
31+
32+
/** Generators whose audit predates the `generate:<x>` / `check:<x>` naming, keyed to that audit. */
33+
const ALIASED_PAIRS: Record<string, string> = {
34+
'skills:sync': 'check:skills',
35+
}
36+
37+
const ROOT = path.resolve(import.meta.dir, '..')
38+
39+
interface GeneratorResult {
40+
script: string
41+
ok: boolean
42+
durationMs: number
43+
}
44+
45+
function generatorScripts(scripts: Record<string, string>): string[] {
46+
return Object.keys(scripts).filter((name) => {
47+
if (name.startsWith('generate:')) return `check:${name.slice('generate:'.length)}` in scripts
48+
const audit = ALIASED_PAIRS[name]
49+
return audit !== undefined && audit in scripts
50+
})
51+
}
52+
53+
/**
54+
* Runs one generator with inherited output.
55+
*
56+
* Spawns the script directly rather than `bun run <name>`, which would start a bun process only
57+
* to have it read package.json and start a second one.
58+
*/
59+
async function runGenerator(script: string, command: string): Promise<GeneratorResult> {
60+
const startedAt = performance.now()
61+
const argv = command.replace(/^bun run /, '').split(/\s+/)
62+
const proc = Bun.spawn([process.execPath, ...argv], {
63+
cwd: ROOT,
64+
stdout: 'inherit',
65+
stderr: 'inherit',
66+
})
67+
const exitCode = await proc.exited
68+
return { script, ok: exitCode === 0, durationMs: performance.now() - startedAt }
69+
}
70+
71+
const manifest = await Bun.file(path.join(ROOT, 'package.json')).json()
72+
const commands = manifest.scripts as Record<string, string>
73+
const generators = generatorScripts(commands)
74+
const results: GeneratorResult[] = []
75+
76+
for (const script of generators) {
77+
console.log(`\n▶ ${script}`)
78+
results.push(await runGenerator(script, commands[script]))
79+
}
80+
81+
console.log(`\n${results.length} generators:`)
82+
for (const result of results) {
83+
console.log(`${result.ok ? '✓' : '✗'} ${result.script} (${Math.round(result.durationMs)}ms)`)
84+
}
85+
86+
const failures = results.filter((result) => !result.ok)
87+
if (failures.length > 0) {
88+
console.error(
89+
`\n${failures.length} generator(s) failed: ${failures.map((f) => f.script).join(', ')}. Their output is above; fix the cause and rerun \`bun run generate\`.`
90+
)
91+
process.exit(1)
92+
}

0 commit comments

Comments
 (0)