From ef3f4b5b03ab534867f05728917e9aa5a2baa756 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 00:36:34 +0000 Subject: [PATCH 1/2] feat(scaffold): new projects run their tests in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bundled template's ci.yml runs `pnpm test` after validate, lint and typecheck. `os init -t app` and `-t empty` declare `test: vitest run`, list vitest, and ship one starter test each (app.test.ts, project.test.ts) that reads the definition, so the CI parity and starter-test pins hold for every scaffolder. The objectstack-project skill's §2 says the CI runs all four. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbWfVxrJ6N3xZaG1Eoe --- .changeset/35218-scaffold-ci-runs-tests.md | 16 +++++ content/docs/deployment/cli.mdx | 2 +- packages/cli/src/commands/init.ts | 61 ++++++++++++++++++- .../cli/test/generate-scaffold-wiring.test.ts | 5 +- .../init-scaffold-authoring-rules.test.ts | 5 +- .../test/scaffold-test-script-passes.test.ts | 2 +- .../src/template-ci-workflow.test.ts | 6 +- .../templates/blank/.github/workflows/ci.yml | 5 ++ skills/objectstack-project/SKILL.md | 6 +- 9 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 .changeset/35218-scaffold-ci-runs-tests.md diff --git a/.changeset/35218-scaffold-ci-runs-tests.md b/.changeset/35218-scaffold-ci-runs-tests.md new file mode 100644 index 00000000000..83817e31ad1 --- /dev/null +++ b/.changeset/35218-scaffold-ci-runs-tests.md @@ -0,0 +1,16 @@ +--- +'create-objectstack': patch +'@objectstack/cli': patch +'@objectstack/skills': patch +--- + +feat(scaffold): new projects run their tests in CI + +Clause-②: no +Metadata-protocol: none + +`npm create objectstack` projects now run `pnpm test` in `.github/workflows/ci.yml`, after `validate`, `lint` and `typecheck`, so the starter `note.test.ts` and every test you add run on each push. + +`os init -t app` and `os init -t empty` now declare a `test` script (`vitest run`), list `vitest` in `devDependencies`, and ship one starter test (`app.test.ts`, `project.test.ts`) that reads the project's definition, so the same CI workflow passes on a project made either way. To test what the engine does with a record, add `@objectstack/verify` and boot the stack with `bootStack`; the `objectstack-project` skill shows how. + +Existing projects are not changed. To take the CI step, add `- run: pnpm test` after `- run: pnpm typecheck` in your `ci.yml`; a project with no `test` script adds vitest and the script first. diff --git a/content/docs/deployment/cli.mdx b/content/docs/deployment/cli.mdx index e21f6117ccf..a71bb211861 100644 --- a/content/docs/deployment/cli.mdx +++ b/content/docs/deployment/cli.mdx @@ -147,7 +147,7 @@ os init my-app --no-install # Skip dependency installation |----------|-----------------| | `app` | Full application with objects, barrel imports | | `plugin` | **Metadata package**: declarative objects, built by `objectstack compile`, `private` — *not* the kernel code plugin `os create plugin` emits | -| `empty` | Minimal project with just `objectstack.config.ts` | +| `empty` | Minimal project: `objectstack.config.ts` and one starter test | The `app` and `plugin` templates declare their starter object with `ObjectSchema.create({ … })` — the one authorised shape for a `*.object.ts`, and the diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index ad4f50ac50f..60040251a25 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -975,6 +975,7 @@ export const TEMPLATES: Record `import { defineStack } from '@objectstack/spec'; @@ -1022,6 +1024,35 @@ ${renderWiredStackKeys()} }); `, srcFiles: withWiredBarrels({ + // The starter test the `test` script runs (#35218); the plugin template's + // `package.test.ts` is the same shape and says why one has to ship. + 'app.test.ts': () => `import { describe, expect, it } from 'vitest'; +import stack from './objectstack.config'; +import * as objects from './src/objects'; + +// Importing objectstack.config.ts runs defineStack(), which checks the +// definition against the ObjectStack protocol and throws on anything the +// protocol refuses, so a definition the platform would refuse fails this file +// before any test in it runs. +// +// The test below reads what the app declares. To test what the engine does +// with a record (a required field refused, the rule a hook enforces, who sees +// which rows), add @objectstack/verify and boot the stack with bootStack; the +// objectstack-project skill shows how. +describe('this app', () => { + it('is an app that hands every object in src/objects to the stack', () => { + expect(stack.manifest?.type).toBe('app'); + + // An object src/objects/index.ts exports is loaded only when the config + // hands it to the stack. One the config drops is never loaded, and + // \`objectstack validate\` neither counts nor checks it. + const loaded = (stack.objects ?? []).map((object) => object.name); + for (const object of Object.values(objects)) { + expect(loaded).toContain(object.name); + } + }); +}); +`, 'src/objects/index.ts': (_name, namespace) => starterObjectExport(namespace), 'src/objects/__name___item.object.ts': (_name, namespace) => `import { ObjectSchema, Field } from '@objectstack/spec/data'; @@ -1270,7 +1301,7 @@ describe('this package', () => { }, empty: { - description: 'Minimal project with just a config file', + description: 'Minimal project: a config file and one starter test', get dependencies() { return { '@objectstack/spec': pkgVersion(), @@ -1280,12 +1311,14 @@ describe('this package', () => { return { '@objectstack/cli': pkgVersion(), 'typescript': SCAFFOLD_TYPESCRIPT_RANGE, + 'vitest': SCAFFOLD_VITEST_RANGE, }; }, scripts: { build: 'objectstack compile', validate: 'objectstack validate', lint: 'objectstack lint', + test: 'vitest run', typecheck: 'tsc --noEmit', }, configContent: (name: string, namespace: string) => `import { defineStack } from '@objectstack/spec'; @@ -1315,7 +1348,31 @@ export default defineStack({ }, }); `, - srcFiles: {}, + // The starter test the `test` script runs (#35218): the bundled template's + // CI runs `pnpm test`, and a `test` script with no test file fails (see the + // plugin template's `package.test.ts`). It reads the definition only; the + // comment points at `bootStack` for tests that need the engine. + srcFiles: { + 'project.test.ts': () => `import { describe, expect, it } from 'vitest'; +import stack from './objectstack.config'; + +// Importing objectstack.config.ts runs defineStack(), which checks the +// definition against the ObjectStack protocol and throws on anything the +// protocol refuses, so a definition the platform would refuse fails this file +// before any test in it runs. +// +// The test below reads what the project declares. To test what the engine +// does with a record (a required field refused, the rule a hook enforces, who +// sees which rows), add @objectstack/verify and boot the stack with bootStack; +// the objectstack-project skill shows how. +describe('this project', () => { + it('declares an app with a namespace', () => { + expect(stack.manifest?.type).toBe('app'); + expect(stack.manifest?.namespace).toBeTruthy(); + }); +}); +`, + }, }, }; diff --git a/packages/cli/test/generate-scaffold-wiring.test.ts b/packages/cli/test/generate-scaffold-wiring.test.ts index 5153e60ac9e..710f1b3cca5 100644 --- a/packages/cli/test/generate-scaffold-wiring.test.ts +++ b/packages/cli/test/generate-scaffold-wiring.test.ts @@ -224,7 +224,8 @@ describe('[#20215] the `app` and `plugin` templates wire every generator barrel' }); it('`empty` stays a bare config: it writes no directory to wire', () => { - expect(Object.keys(TEMPLATES.empty.srcFiles)).toEqual([]); + // Its one file is the root-level starter test (#35218), outside `src/`. + expect(Object.keys(TEMPLATES.empty.srcFiles).filter((f) => f.includes('/'))).toEqual([]); expect(TEMPLATES.empty.configContent(PROJECT, NS)).not.toContain('import * as'); }); }); @@ -400,7 +401,7 @@ describe('[#32212] a scaffolded project lists its objects in an app, each with a }); it('`empty`: scaffolds no object, so it has nothing for an app or a view to name', () => { - expect(Object.keys(TEMPLATES.empty.srcFiles)).toEqual([]); + expect(Object.keys(TEMPLATES.empty.srcFiles).filter((f) => f.startsWith('src/'))).toEqual([]); }); // The route the card asked to be named: the object is referenced through an diff --git a/packages/cli/test/init-scaffold-authoring-rules.test.ts b/packages/cli/test/init-scaffold-authoring-rules.test.ts index 85313fd80db..07d6017bf7a 100644 --- a/packages/cli/test/init-scaffold-authoring-rules.test.ts +++ b/packages/cli/test/init-scaffold-authoring-rules.test.ts @@ -110,8 +110,11 @@ describe('init scaffolds pass the author-time rules `dev` runs', () => { // The reported instance, pinned by name so a future template edit that drops // the field fails with the incident's own vocabulary rather than a bare count. + // Roster: every template that emits an object file. `empty` emits a starter + // test and no object (#35218), so "has srcFiles" no longer means "has objects". it.each( - Object.keys(TEMPLATES).filter((k) => Object.keys(TEMPLATES[k].srcFiles).length > 0), + Object.keys(TEMPLATES).filter((k) => + Object.keys(TEMPLATES[k].srcFiles).some((f) => f.includes('src/objects/') && !f.endsWith('index.ts'))), )('template "%s" declares an authored OWD on every object it emits', (templateKey) => { const namespace = sanitizeNamespace(PROJECT_NAME); const objectSources = Object.entries(TEMPLATES[templateKey].srcFiles) diff --git a/packages/cli/test/scaffold-test-script-passes.test.ts b/packages/cli/test/scaffold-test-script-passes.test.ts index ba77c536dbb..cef061f1454 100644 --- a/packages/cli/test/scaffold-test-script-passes.test.ts +++ b/packages/cli/test/scaffold-test-script-passes.test.ts @@ -1,5 +1,5 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. -// test-budget: 20 — spawns the real producer once per single-cause fixture: eight spawns of the emitted projects' own scripts, each on its own fixture state (five `test` runs through vitest: init plugin, its empty-suite control, create plugin fresh, after `build`, and its empty-suite control; three tsc runs: `build`, `typecheck` clean and `typecheck` with the planted error); slowest CI reading 14.9 s (run 41217827347) of the five scheduled ci.yml runs 41199450735 to 41271604267 (slice 23's offender table), x 1.25, rounded up +// test-budget: 20 — spawns the real producer once per single-cause fixture: ten spawns of the emitted projects' own scripts, each on its own fixture state (seven `test` runs through vitest: init app, plugin and empty, the init empty-suite control, create plugin fresh, after `build`, and its empty-suite control; three tsc runs: `build`, `typecheck` clean and `typecheck` with the planted error); slowest CI reading 14.9 s (run 41217827347) of the five scheduled ci.yml runs 41199450735 to 41271604267 (slice 23's offender table), x 1.25, rounded up /** * PIN (#25175) — an `os init` template that declares a `test` script ships a diff --git a/packages/create-objectstack/src/template-ci-workflow.test.ts b/packages/create-objectstack/src/template-ci-workflow.test.ts index f470a417fb0..839b58968bd 100644 --- a/packages/create-objectstack/src/template-ci-workflow.test.ts +++ b/packages/create-objectstack/src/template-ci-workflow.test.ts @@ -146,7 +146,7 @@ describe('bundled template CI workflow', () => { ).toContain(script); } - // The three gates this workflow exists to run. `lint` is here on a + // The gates this workflow exists to run. `lint` is here on a // MEASUREMENT, not on the card's wording: scaffolded for real from the // repo-built scaffolder, `npm install` against the registry, then // `npm run lint` -> exit 0, "All checks passed". It is not a second @@ -156,6 +156,10 @@ describe('bundled template CI workflow', () => { expect(invoked).toContain('validate'); expect(invoked).toContain('lint'); expect(invoked).toContain('typecheck'); + // `test` (#35218): the starter `note.test.ts` and every test the app adds. + // The other scaffolder declares it too, with a starter test per template, + // which `packages/cli/test/scaffold-test-script-passes.test.ts` runs. + expect(invoked).toContain('test'); }); // Derived from the Dockerfile's build stage rather than restated: the diff --git a/packages/create-objectstack/src/templates/blank/.github/workflows/ci.yml b/packages/create-objectstack/src/templates/blank/.github/workflows/ci.yml index 18a128d1997..a1e2d661e59 100644 --- a/packages/create-objectstack/src/templates/blank/.github/workflows/ci.yml +++ b/packages/create-objectstack/src/templates/blank/.github/workflows/ci.yml @@ -65,3 +65,8 @@ jobs: - run: pnpm lint - run: pnpm typecheck + + # The app's own tests: business facts the platform cannot derive, pinned + # against the real engine with `bootStack` (`note.test.ts` is the shape). + # The three gates above check consistency; this checks intent. + - run: pnpm test diff --git a/skills/objectstack-project/SKILL.md b/skills/objectstack-project/SKILL.md index 973235b1481..0943088e926 100644 --- a/skills/objectstack-project/SKILL.md +++ b/skills/objectstack-project/SKILL.md @@ -74,9 +74,9 @@ which automation fires · which screens change · translations · ## 2 · Testing: what the app pins, what the platform checks The platform checks consistency. The app tests its own business facts. Run all -four before calling a change done (a scaffolded project's CI runs the first -three; add `pnpm test` to its `ci.yml`). A project from `os init` has no `test` -script: add vitest, `@objectstack/verify` and the script first. +four before calling a change done; a scaffolded project's CI runs them (an +older scaffold may lack the `pnpm test` step: add it). No `test` script? Add +vitest, `@objectstack/verify` and the script. Only errors fail `validate` and `lint`; a warning, such as label case or an unresolved navigation target, passes. `--strict` on either makes warnings fail: use it instead of re-checking them in a test. From bffdcfc9cdd53804a136f77f74579d20ac0df295 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 01:10:57 +0000 Subject: [PATCH 2/2] fix: close the contract review's should-fixes on the scaffold CI step - S1: the starter-test file's budget is re-measured for ten spawns (local 11.6 s -> 16.4 s against eight, scaled from the 14.9 s CI reading) and declared at 30. - S2: the skill tells every project to add `@objectstack/verify` where it is missing, not only a project without a `test` script. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbWfVxrJ6N3xZaG1Eoe --- packages/cli/test/scaffold-test-script-passes.test.ts | 2 +- skills/objectstack-project/SKILL.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/test/scaffold-test-script-passes.test.ts b/packages/cli/test/scaffold-test-script-passes.test.ts index cef061f1454..32fd5261e3c 100644 --- a/packages/cli/test/scaffold-test-script-passes.test.ts +++ b/packages/cli/test/scaffold-test-script-passes.test.ts @@ -1,5 +1,5 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. -// test-budget: 20 — spawns the real producer once per single-cause fixture: ten spawns of the emitted projects' own scripts, each on its own fixture state (seven `test` runs through vitest: init app, plugin and empty, the init empty-suite control, create plugin fresh, after `build`, and its empty-suite control; three tsc runs: `build`, `typecheck` clean and `typecheck` with the planted error); slowest CI reading 14.9 s (run 41217827347) of the five scheduled ci.yml runs 41199450735 to 41271604267 (slice 23's offender table), x 1.25, rounded up +// test-budget: 30 — spawns the real producer once per single-cause fixture: ten spawns of the emitted projects' own scripts, each on its own fixture state (seven `test` runs through vitest: init app, plugin and empty, the init empty-suite control, create plugin fresh, after `build`, and its empty-suite control; three tsc runs: `build`, `typecheck` clean and `typecheck` with the planted error); CI reading 14.9 s at eight spawns (run 41217827347, slice 23's offender table); measured locally on this change at 11.6 s with eight spawns and 16.4 s with ten (x 1.41), so about 21.0 s on CI, x 1.25, rounded up /** * PIN (#25175) — an `os init` template that declares a `test` script ships a diff --git a/skills/objectstack-project/SKILL.md b/skills/objectstack-project/SKILL.md index 0943088e926..17c7a1166e8 100644 --- a/skills/objectstack-project/SKILL.md +++ b/skills/objectstack-project/SKILL.md @@ -75,8 +75,8 @@ which automation fires · which screens change · translations · The platform checks consistency. The app tests its own business facts. Run all four before calling a change done; a scaffolded project's CI runs them (an -older scaffold may lack the `pnpm test` step: add it). No `test` script? Add -vitest, `@objectstack/verify` and the script. +older scaffold may lack the `pnpm test` step: add it). Add vitest, the `test` +script and `@objectstack/verify` (for `bootStack`) where missing. Only errors fail `validate` and `lint`; a warning, such as label case or an unresolved navigation target, passes. `--strict` on either makes warnings fail: use it instead of re-checking them in a test.