Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/35218-scaffold-ci-runs-tests.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 59 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ export const TEMPLATES: Record<string, {
return {
'@objectstack/cli': pkgVersion(),
'typescript': SCAFFOLD_TYPESCRIPT_RANGE,
'vitest': SCAFFOLD_VITEST_RANGE,
};
},
scripts: {
Expand All @@ -989,6 +990,7 @@ export const TEMPLATES: Record<string, {
deploy: 'objectstack deploy',
validate: 'objectstack validate',
lint: 'objectstack lint',
test: 'vitest run',
typecheck: 'tsc --noEmit',
},
configContent: (name: string, namespace: string) => `import { defineStack } from '@objectstack/spec';
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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(),
Expand All @@ -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';
Expand Down Expand Up @@ -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();
});
});
`,
},
},
};

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/test/generate-scaffold-wiring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/test/init-scaffold-authoring-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/scaffold-test-script-passes.test.ts
Original file line number Diff line number Diff line change
@@ -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: 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
Expand Down
6 changes: 5 additions & 1 deletion packages/create-objectstack/src/template-ci-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions skills/objectstack-project/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). 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.
Expand Down
Loading