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
20 changes: 20 additions & 0 deletions .changeset/35132-gallery-trial-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/scenarios': patch
---

feat(scenarios): the gallery export writes each app as a package a customer can install and try (listing text, business-function facet, sample data), and the gallery check refuses an app with no sample data

Clause-②: yes
Metadata-protocol: none

The exporter now adds three things to each app's `source/`. It adds them after the run is scored, so the AI's build is never graded on them, and it never writes them into the run's own project.

- `objectstack.manifest.json` gets the card's listing text and facet. `displayName` and `description` are the card's English title and one-sentence requirement. The Chinese pair goes under `translations.zh`. `businessFunctions` is the card's own list, primary first. The build's other keys are kept.
- `src/sample-data.json` holds the card's seed rows as stack `data:` datasets: one per object, named with the app's namespace, keyed on the card's row id (`externalId: 'id'`). Lookup values name row ids of the same load. A user-handle field (`run.userHandleFields`) is left out of every row, because its value names a user of the run's own environment, and the app README says which field was left out.
- `objectstack.config.ts` gets one import line and `data: gallerySampleData` as the first property of its default-exported `defineStack({ … })` literal. Every other byte stays as the AI wrote it. The export is refused, with the reason, in four cases: the default export is not such a literal, the literal already declares `data:` or spreads a value, a seeded object is missing from the build, or the build already wrote `src/sample-data.json`.

Measured on `travel_expense`: the blank scaffold's `objectstack.config.ts`, with the recorded build's objects and the 757 seed rows added this way, passes `objectstack validate`. A dataset naming an object the build lacks is refused there ("Seed data references object … which is not defined in objects"), which shows the validator reads the imported file.

`export-gallery --check` has a new finding, `app-sample-data`. It reports an app whose `source/` has no `src/sample-data.json`, a file that is not a non-empty list of datasets the spec's `SeedSchema` accepts (each with at least one record), or a `source/objectstack.config.ts` that does not import it. A gallery tree written by an earlier exporter has no sample-data file, so the check reports each of its apps until the next refresh exports them again. The check writes nothing and deletes no app.

`installModes` and `solutionType` are not written yet: `installModes: ['unmanaged']` makes `defineStack` refuse an app that carries code `plugins` or `capability` items, which an app on the standard scaffold does. `typescript` moves from a dev dependency to a dependency. The exporter loads it, with a dynamic import, only when it edits a config.
13 changes: 11 additions & 2 deletions packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,14 @@ that version, it prints one `skip: …` line and exits 0, having run nothing. It
1. runs every card the gallery may show (origin `generic`, tier `starter` or `delivery`; `--debut`: the first of them
by id) with `run-scenarios --modes scratch --packages published --create-version <version>`, so the apps are built
on exactly that release, the turns recorded;
2. exports with screenshots into the checkout (`export-gallery`'s rules: only a run that passed every half);
2. exports with screenshots into the checkout (`export-gallery`'s rules: only a run that passed every half). Each
app's `source/` is written as a package a customer installs to try, after scoring so the build is never graded on
it (`src/export/trial-package.ts`): `objectstack.manifest.json` carries the card's English title and one-sentence
requirement as `displayName` and `description`, the Chinese pair under `translations.zh`, and the card's
`businessFunctions`; `src/sample-data.json` carries the card's seed rows as stack `data:` datasets (namespaced
objects, `externalId: 'id'`, a user-handle field left out), which `objectstack.config.ts` imports into its `data:`.
`installModes` and `solutionType` are not written: `installModes: ['unmanaged']` makes `defineStack` refuse an app
that carries code `plugins` or `capability` items, which an app on the standard scaffold does;
3. creates the branch `export/<version>`, commits `apps/` and `index.json` under the checkout's own git identity, and
prints the branch, the commit and a ready PR body.

Expand Down Expand Up @@ -786,7 +793,9 @@ The check a PR on objectstack-ai/gallery must pass before it is merged (`src/exp
layout), so the two cannot drift. It prints one `CODE PATH: MESSAGE` line per finding and exits 1 on any, 0 on a clean
tree: `index.json` that does not validate (absent is an empty gallery); an entry without a complete `apps/<id>/`
(README, run record, scorecard and transcript in JSON and Markdown, `source/objectstack.config.ts`, at least one
screenshot, every listed screenshot on disk and none unlisted); a directory under `apps/` no entry lists; a
screenshot, every listed screenshot on disk and none unlisted); an app whose package arrives with no sample data (no
`source/src/sample-data.json`, one that is not a non-empty list of stack `data:` datasets the spec's `SeedSchema`
accepts, each with a record, or a `source/objectstack.config.ts` that does not import it); a directory under `apps/` no entry lists; a
`framework.version` that is not a stable release published for `@objectstack/cli` (read with `npm view … versions`,
only when the index lists an app); and anywhere in the tree a `.env*` name, a `node_modules` directory, a symbolic link
or a text file naming a local absolute path.
Expand Down
2 changes: 1 addition & 1 deletion packages/qa/scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
"@objectstack/plugin-sharing": "workspace:*",
"@objectstack/spec": "workspace:*",
"playwright-core": "1.63.0",
"typescript": "^6.0.3",
"zod": "^4.6.6"
},
"devDependencies": {
"@types/node": "^26.6.5",
"typescript": "^6.0.3",
"vitest": "^4.1.11"
},
"keywords": [
Expand Down
47 changes: 46 additions & 1 deletion packages/qa/scenarios/src/export/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* the README, the run record, the scorecard and the
* transcript (JSON and Markdown each), and a `source/` tree
* holding `objectstack.config.ts`.
* app-sample-data an entry's package arrives with no sample data: its
* `source/` holds no {@link SAMPLE_DATA_FILE}, the file is
* not a non-empty list of stack `data:` datasets (each
* valid against the spec's `SeedSchema`, each with at
* least one record), or `source/objectstack.config.ts`
* does not import it ({@link SAMPLE_DATA_SPECIFIER}).
* app-screenshots an entry lists no screenshot, a listed screenshot is not
* on disk, or `screenshots/` holds a file the entry does
* not list.
Expand Down Expand Up @@ -49,13 +55,16 @@ import { execFileSync } from 'node:child_process';
import { existsSync, lstatSync, readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';

import { APP_LAYOUT, FRAMEWORK_PACKAGE, STABLE_VERSION } from './contract.js';
import { SeedSchema } from '@objectstack/spec/data';

import { APP_LAYOUT, FRAMEWORK_PACKAGE, SAMPLE_DATA_FILE, SAMPLE_DATA_SPECIFIER, STABLE_VERSION } from './contract.js';
import { GalleryIndexSchema, type GalleryApp } from './manifest.js';

export const FINDING_CODES = [
'index-json',
'app-missing',
'app-incomplete',
'app-sample-data',
'app-screenshots',
'app-unlisted',
'framework-version',
Expand Down Expand Up @@ -162,6 +171,7 @@ export function checkGallery(dir: string, opts: CheckOptions): GalleryFinding[]
if (!isFile(join(root, APP_LAYOUT.source, SOURCE_REQUIRED))) {
add('app-incomplete', `${rel}/${APP_LAYOUT.source}`, `a complete app directory holds its metadata source, ${APP_LAYOUT.source}/${SOURCE_REQUIRED} at least, and this one does not`);
}
checkSampleData(dir, app, add);
checkScreenshots(dir, app, add);
}
const v = app.framework.version;
Expand All @@ -181,6 +191,41 @@ export function checkGallery(dir: string, opts: CheckOptions): GalleryFinding[]
return findings;
}

/** The sample data a trial package arrives with: present, a valid non-empty dataset list, and read by the config. */
function checkSampleData(dir: string, app: GalleryApp, add: AddFinding): void {
const source = `apps/${app.id}/${APP_LAYOUT.source}`;
const config = join(dir, source, SOURCE_REQUIRED);
if (!isFile(config)) return; // an incomplete source is `app-incomplete` already
const rel = `${source}/${SAMPLE_DATA_FILE}`;
const file = join(dir, rel);
if (!isFile(file)) {
add('app-sample-data', rel, `a gallery app is a package a customer installs to try, and it arrives with the card's seed rows as its sample data in ${APP_LAYOUT.source}/${SAMPLE_DATA_FILE}; this one has none`);
return;
}
let raw: unknown;
try {
raw = JSON.parse(readFileSync(file, 'utf8'));
} catch (e) {
add('app-sample-data', rel, `not JSON: ${e instanceof Error ? e.message : String(e)}`);
return;
}
if (!Array.isArray(raw) || raw.length === 0) {
add('app-sample-data', rel, 'the sample data is a non-empty list of stack `data:` datasets, and this is not one');
return;
}
raw.forEach((dataset, i) => {
const parsed = SeedSchema.safeParse(dataset);
if (!parsed.success) {
for (const issue of parsed.error.issues) add('app-sample-data', rel, `[${i}]${issue.path.length ? `.${issue.path.join('.')}` : ''}: ${issue.message}`);
} else if (parsed.data.records.length === 0) {
add('app-sample-data', rel, `[${i}] (\`${parsed.data.object}\`) holds no record`);
}
});
if (!readFileSync(config, 'utf8').includes(`'${SAMPLE_DATA_SPECIFIER}'`)) {
add('app-sample-data', `${source}/${SOURCE_REQUIRED}`, `does not import '${SAMPLE_DATA_SPECIFIER}' into its \`data:\`, so the package installs without its sample data`);
}
}

function checkScreenshots(dir: string, app: GalleryApp, add: AddFinding): void {
const rel = `apps/${app.id}/${APP_LAYOUT.screenshots}`;
if (app.screenshots.length === 0) add('app-screenshots', rel, `index.json lists no screenshot for \`${app.id}\`: an app is shown with its screenshots`);
Expand Down
11 changes: 11 additions & 0 deletions packages/qa/scenarios/src/export/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export const APP_LAYOUT = {
screenshots: 'screenshots',
} as const;

/**
* The trial package's sample data, relative to `apps/<id>/source/`: the card's
* seed rows as stack `data:` datasets (`trial-package.ts`), which the check
* requires (`app-sample-data`).
*/
export const SAMPLE_DATA_FILE = 'src/sample-data.json';

/** How `source/objectstack.config.ts` imports {@link SAMPLE_DATA_FILE}: the specifier, and the name it binds. */
export const SAMPLE_DATA_SPECIFIER = `./${SAMPLE_DATA_FILE}`;
export const SAMPLE_DATA_BINDING = 'gallerySampleData';

/** The package whose npm `latest` is the framework release the gallery follows. */
export const FRAMEWORK_PACKAGE = '@objectstack/cli';

Expand Down
22 changes: 16 additions & 6 deletions packages/qa/scenarios/src/export/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
* 2. ⛔ the run was on published packages ({@link unpublishedRunRefusal}): a
* `--packages workspace` run is never exported or shown;
* 3. the record passed every half ({@link judgeRecord});
* 4. the run's scratch project is still on disk, with its build;
* 4. the run's scratch project is still on disk, with its build, and its
* source can be made the trial package ({@link trialPackageSource}): its
* config default-exports a `defineStack({ … })` literal that declares no
* `data:` of its own, and the build declares every object the card seeds;
* 5. its transcript joins with the recording ({@link buildTranscript});
* 6. its screenshots were taken, unless the caller turned them off.
*
Expand All @@ -22,7 +25,9 @@
*
* apps/<id>/README.md what the app is, the driver that ran it ({@link driverText}), what its authoring cost
* ({@link authorCostText}: stated only when every authoring turn reported a cost), its scorecard, the files
* apps/<id>/source/… the authored metadata source (`source.ts`)
* apps/<id>/source/… the authored metadata source (`source.ts`), as a trial package: the
* card's listing text, facet and sample data added after scoring
* (`trial-package.ts`)
* apps/<id>/run-record.json the run record, the work directories redacted (`workDirsOf`)
* apps/<id>/scorecard.json|.md the per-half scorecard
* apps/<id>/transcript.json|.md the per-persona 问数 transcript
Expand Down Expand Up @@ -59,6 +64,7 @@ import { judgeRecord, type PassJudgement } from './pass.js';
import { readRunRecords, redactWorkDir, unpublishedRunRefusal, type RecordFile, type ScenarioRunRecord } from './record.js';
import type { CaptureScreenshots, PlannedShot, SkippedShot } from './screenshots.js';
import { projectFrameworkVersion, readAuthoredSource } from './source.js';
import { SAMPLE_DATA_FILE, trialPackageSource } from './trial-package.js';
import { buildTranscript, mergeRecordings, renderTranscript } from './transcript.js';

/** The files of one exported app, relative to `apps/<id>/` (`contract.ts`, which the check reads too). */
Expand Down Expand Up @@ -130,7 +136,7 @@ export function driverText(driver: ScenarioRunRecord['env']['driver']): string {
return named(driver);
}

function appReadme(scenario: LoadedScenario, record: ScenarioRunRecord, entry: GalleryApp, judgement: PassJudgement, scorecard: CardScorecard, shots: PlannedShot[], skipped: SkippedShot[]): string {
function appReadme(scenario: LoadedScenario, record: ScenarioRunRecord, entry: GalleryApp, judgement: PassJudgement, scorecard: CardScorecard, shots: PlannedShot[], skipped: SkippedShot[], omitted: readonly string[]): string {
const c = scenario.card;
const lines = [
`# ${c.title.en}`,
Expand All @@ -144,6 +150,7 @@ function appReadme(scenario: LoadedScenario, record: ScenarioRunRecord, entry: G
`- Driver: ${driverText(record.env.driver)}`,
`- Author cost (as the driver reported it): ${authorCostText(scorecard.authorCost)}`,
`- 问数: ${entry.qa.questions} questions, ${entry.qa.turns} persona turns · ${entry.operations} write operations`,
`- Sample data: the card's ${Object.values(c.run.seed).reduce((n, rows) => n + rows.length, 0)} seed rows in ${Object.keys(c.run.seed).length} objects${omitted.length ? `, without ${omitted.map((f) => `\`${f}\``).join(', ')} (a user handle of the run's own environment, left unset)` : ''}`,
'',
'## The requirement',
'',
Expand All @@ -158,7 +165,7 @@ function appReadme(scenario: LoadedScenario, record: ScenarioRunRecord, entry: G
'',
'## Files',
'',
`- [\`${APP_LAYOUT.source}/\`](./${APP_LAYOUT.source}/) — the app's metadata source, as the AI wrote it (after the change request)`,
`- [\`${APP_LAYOUT.source}/\`](./${APP_LAYOUT.source}/) — the app's metadata source, as the AI wrote it (after the change request), with the package's listing text in \`objectstack.manifest.json\` and the card's seed rows as its sample data (\`${SAMPLE_DATA_FILE}\`, read into \`data:\`), both added after scoring`,
`- [\`${APP_LAYOUT.transcriptMd}\`](./${APP_LAYOUT.transcriptMd}) — every data question, each persona's answer and its grade ([JSON](./${APP_LAYOUT.transcriptJson}))`,
`- [\`${APP_LAYOUT.scorecardMd}\`](./${APP_LAYOUT.scorecardMd}) — the scorecard ([JSON](./${APP_LAYOUT.scorecardJson}))`,
`- [\`${APP_LAYOUT.runRecord}\`](./${APP_LAYOUT.runRecord}) — the full run record`,
Expand Down Expand Up @@ -294,7 +301,10 @@ async function exportOne(
if (!existsSync(projectDir)) throw new Refused([`the run's scratch project is gone: ${projectDir}`]);
const artifact = readArtifact(projectDir);
if (artifact === undefined) throw new Refused([`${projectDir} holds no dist/objectstack.json`]);
const source = readAuthoredSource(projectDir);
const authored = readAuthoredSource(projectDir);
// The trial package's listing text, facet and sample data: added to the exported copy only, after scoring.
const builtObjects = new Set(((artifact as { objects?: Array<{ name?: unknown }> }).objects ?? []).map((o) => o?.name).filter((n): n is string => typeof n === 'string'));
const source = await trialPackageSource(authored.files, card, builtObjects);
const frameworkVersion = projectFrameworkVersion(projectDir);
const redact = <T,>(v: T): T => redactWorkDir(v, workDirsOf(record.evidenceDir, opts.workDir));
const transcript = redact(buildTranscript(scenario, record, turns));
Expand Down Expand Up @@ -332,7 +342,7 @@ async function exportOne(
[APP_LAYOUT.scorecardMd, `${renderScorecard(scorecard)}\n`],
[APP_LAYOUT.transcriptJson, json(transcript)],
[APP_LAYOUT.transcriptMd, renderTranscript(transcript, card.title.en)],
[APP_LAYOUT.readme, redact(appReadme(scenario, record, entry, judgement, scorecard, shots, skipped))],
[APP_LAYOUT.readme, redact(appReadme(scenario, record, entry, judgement, scorecard, shots, skipped, source.omitted))],
]);
return { entry, shots, skipped };
}
1 change: 1 addition & 0 deletions packages/qa/scenarios/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './refresh.js';
export * from './screenshots.js';
export * from './source.js';
export * from './transcript.js';
export * from './trial-package.js';
Loading
Loading