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
10 changes: 10 additions & 0 deletions .changeset/36073-masking-off-ask-round.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/scenarios': patch
---

feat(scenarios): `--schema-masking off` runs a recorded masking-off round, so the field-level-security question can be asked on the open cards

Clause-②: yes (widening) — the new CLI flag `--schema-masking on|off` on `objectstack-scenarios run` / `run-scenarios` (`cli.ts`); through `./runner`, the new module `schema-masking.ts` and its exports `SCHEMA_MASKING_SETTINGS`, `SchemaMasking`, `schemaMaskingRefusal`, `roundSchemaMasking`, `schemaMaskingHostEnv` and `schemaMaskingText`, the new optional field `RunRecordMeta.schemaMasking` (`scorecard.ts`), and `TABLE_DIMENSIONS` gaining `'schema masking'` (`summary.ts`); the new export `bootEnv` and optional field `CliArgs.schemaMasking` of `cli.ts`, reached by the bin's built `cli` entry, not an export-map subpath; the run record's new optional key `env.schemaMasking` (`"off"`), written only by a masking-off round; a new runtime dependency on `@objectstack/metadata-core`, already in the package's dependency closure. A run started as before keeps running: one whose environment sets `OS_ALLOW_UNMASKED_OBJECT_METADATA` to a value that turns masking off now also stamps `env.schemaMasking: "off"` on its records, where it used to run with masking off and say nothing of it.
Metadata-protocol: none

Every app the runner boots masks each caller's object schema to the fields it may read (ADR-0106), and every card persona is a plain member, so a field a card withholds from a persona did not exist for it, and the ruled field-level-security question could not be asked. `--schema-masking off` boots each app of the run with `OS_ALLOW_UNMASKED_OBJECT_METADATA=1` (ADR-0106 D8), on the app's process only. The cards' member-withheld field questions (`department_budgets` asked as `employee`) then grade the ruled way: a reply that the field is not visible to the persona passes, one that calls it blank or empty fails. Every record of such a round carries `env.schemaMasking: "off"`, and `summary` refuses a table whose runs differ in schema masking. The variable exported in the shell (every booted app inherits it) makes a masking-off round too, recorded as one, read with the metadata plane's own predicate; `--schema-masking on` beside it is refused. A default round's record keeps its bytes.
27 changes: 26 additions & 1 deletion packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pnpm --filter @objectstack/scenarios run-scenarios --effort medium # t
pnpm --filter @objectstack/scenarios run-scenarios --author-effort high --ask-effort low # build and persona turns apart
pnpm --filter @objectstack/scenarios run-scenarios --lang zh --prompt short # the card's Chinese texts, and its short build prompt (default: en, else zh; detailed)
pnpm --filter @objectstack/scenarios run-scenarios --packages workspace # on this checkout's unreleased packages (default: published)
pnpm --filter @objectstack/scenarios run-scenarios --modes ask --template dist/objectstack.json --schema-masking off # a masking-off round (below)
pnpm --filter @objectstack/scenarios run-scenarios --modes door --door-skills "$PWD/skills" # build through the MCP draft door, no project (below)
pnpm --filter @objectstack/scenarios run-scenarios --modes door --door-rules builtin # the same, with the built-in authoring rules (below)
```
Expand Down Expand Up @@ -271,7 +272,7 @@ files only: no model, no network, and no score of its own — every figure is th
`this run’s from-scratch build` takes that run's scratch author.
- **Never summed silently**: a table's runs must share the prompt choice, the package source, the ask repeats and the
driver (a replay is its own driver), the ask skills (`--ask-skills`: names and sha256; a record without them
reads `none`), the door arm (`--modes door`, below; a record without one reads `skills: none · rules: none`), and the card file they graded (`card`, below; a record without it reads `card: not recorded`).
reads `none`), the door arm (`--modes door`, below; a record without one reads `skills: none · rules: none`), the card file they graded (`card`, below; a record without it reads `card: not recorded`), and the schema masking of the apps they booted (`--schema-masking off`, below; a record without it reads `schema masking: on`).
When they do not, that table is refused with a line naming each difference and
the files on each side; the other tables print, and the command exits 1. Summarize each side apart.
- **The card stamp**: every record names the card file it graded at its top level, `card: { id, sha256 }` (the sha256
Expand All @@ -288,6 +289,30 @@ files only: no model, no network, and no score of its own — every figure is th
- `--card ID[,ID]` and `--mode M[,M]` narrow the tables. Other JSON in a directory (recordings) is skipped and listed
on stderr; a file named directly that is not a run record fails the command.

### A masking-off round — `--schema-masking off`

By default every app the runner boots masks each caller's object schema to the fields it may read (ADR-0106), and
every card persona is a plain member, so a field the card withholds from a persona does not exist for it: asking
for it is not the field-level-security question. `--schema-masking off` (`src/runner/schema-masking.ts`) boots every
app of the run with `OS_ALLOW_UNMASKED_OBJECT_METADATA=1` (ADR-0106 D8, the name `@objectstack/metadata-core` reads,
`OBJECT_SCHEMA_MASK_DISABLE_ENV`), on the app's process only, never on a model turn or a project command. Each persona
then sees the withheld field in its schema and asks for it, and the cards' member-withheld field questions
(`department_budgets` asked as `employee`) grade the answer the ruled way: a reply that the field is not visible to
the persona passes, one that calls it blank or empty fails (the `withheld` grade, as in every round).

- **Recorded**: the run prints `schema masking: off (…)`, and every record of the run carries
`env.schemaMasking: "off"`. A default round writes no such key, so its record keeps its bytes.
- **Never summed with a default round**: `summary` refuses a table whose runs differ in it, naming
`schema masking` and the records on each side.
- **The shell cannot turn it off unrecorded**: every child the runner spawns inherits its environment, so a run
started with `OS_ALLOW_UNMASKED_OBJECT_METADATA` set and no flag is a masking-off round, and is recorded as one: the
runner reads the variable with the metadata plane's own predicate (`isObjectSchemaMaskingEnabled`), prints
`schema masking: off (…) — set by the environment, not by --schema-masking` and stamps every record. A value the
platform reads as masked (`0`, `false`, blank) stamps nothing. `--schema-masking on` beside a value that turns
masking off is refused before any card runs.
- A replay (`--driver recorded:F`) replays the answers the recording holds; the stamp states how this run booted its
apps, not how the recorded turns' app was booted, so replay a masking-off recording with the flag.

### Door mode — `--modes door`

Door mode builds the card the way a person's own MCP client builds an app on a running environment: through the
Expand Down
1 change: 1 addition & 0 deletions packages/qa/scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@objectstack/core": "workspace:*",
"@objectstack/formula": "workspace:*",
"@objectstack/lint": "workspace:*",
"@objectstack/metadata-core": "workspace:*",
"@objectstack/objectql": "workspace:*",
"@objectstack/plugin-sharing": "workspace:*",
"@objectstack/spec": "workspace:*",
Expand Down
41 changes: 38 additions & 3 deletions packages/qa/scenarios/src/runner/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
* `workspace` — this checkout, built and packed as the
* release would publish it (unreleased; never exported;
* refused when run from the published package, which has no checkout)
* --schema-masking off boot every app of the run with object-schema masking
* off (ADR-0106 D8, `schema-masking.ts`), so a persona
* is served its whole schema and a field the card
* withholds from it is the field-level-security
* question; every record of the run says so
* (`env.schemaMasking`), and `summary` never sums it
* with a default run (default `on`: masked, nothing
* stamped). With no flag, the masking variable set in
* the environment makes the run a masking-off round,
* recorded as one; `on` beside it is refused
*
* `run-scenarios summary <record|dir>…` (`objectstack-scenarios summary`) reads
* run records back instead and prints one author-model × ask-model table per
Expand Down Expand Up @@ -148,6 +158,7 @@ import { installedSpecVersion, PACKAGES_MODES, prepareWorkspacePackages, settleW
import { bootDev, os, readArtifact, readNamespace, scaffold } from './project.js';
import { PROMPT_LANGS, PROMPT_LENGTHS, promptChoiceText, promptLanguageRefusal, statedPromptChoice, type PromptChoice, type PromptLang, type PromptLength } from './prompts.js';
import { rebaseScenario } from './run-date.js';
import { roundSchemaMasking, SCHEMA_MASKING_SETTINGS, schemaMaskingHostEnv, schemaMaskingRefusal, schemaMaskingText, type SchemaMasking } from './schema-masking.js';
import { cardScorecard, renderScorecard, runRecord, type CardStamp } from './scorecard.js';
import { SUPPLIED_TEMPLATE_SOURCE, summaryMain, suppliedTemplateOf, type SuppliedTemplate } from './summary.js';

Expand Down Expand Up @@ -214,6 +225,8 @@ export interface CliArgs {
lang?: PromptLang;
/** `--prompt`: the card prompt the build turn is given ({@link PromptChoice.prompt}); absent ⇒ `detailed`. */
prompt?: PromptLength;
/** `--schema-masking`: `off` boots every app of the run with object-schema masking off and stamps its records ({@link SchemaMasking}); `on` ⇒ masked; absent ⇒ masked unless the environment turns it off (`roundSchemaMasking`). */
schemaMasking?: SchemaMasking;
}

export function parseArgs(argv: readonly string[]): CliArgs {
Expand Down Expand Up @@ -293,6 +306,11 @@ export function parseArgs(argv: readonly string[]): CliArgs {
if (!(PROMPT_LENGTHS as readonly string[]).includes(p)) throw new Error(`unknown --prompt \`${p}\` (${PROMPT_LENGTHS.join(', ')})`);
a.prompt = p as PromptLength;
}
else if (flag === '--schema-masking') {
const m = val();
if (!(SCHEMA_MASKING_SETTINGS as readonly string[]).includes(m)) throw new Error(`unknown --schema-masking \`${m}\` (${SCHEMA_MASKING_SETTINGS.join(', ')})`);
a.schemaMasking = m as SchemaMasking;
}
else if (flag === '--out') a.out = val();
else if (flag === '--work') a.work = val();
else if (flag === '--create-version') a.createVersion = val();
Expand Down Expand Up @@ -421,6 +439,17 @@ export function makeDriver(spec: string, opts: DriverLimits & DriverModels & Dri
throw new Error(`unknown driver \`${spec}\` (claude, codex, external:COMMAND, recorded:FILE)`);
}

/**
* What a booted app's environment gains over the runner's own: door mode's
* host serves the OAuth authorization server its client's token comes from,
* and a masking-off round sets the D8 opt-out (`schema-masking.ts`) on the
* app's process alone, never on a model turn or a project command. `{}` on a
* default round outside door mode, as before the flag.
*/
export function bootEnv(args: Pick<CliArgs, 'schemaMasking'>, authoringDoor: boolean | undefined): Record<string, string> {
return { ...(authoringDoor ? { OS_OIDC_PROVIDER_ENABLED: 'true' } : {}), ...schemaMaskingHostEnv(args.schemaMasking) };
}

/**
* The record with its supplied template named (`template`, top level), when a
* template or ask mode of the run installed the `--template` file; the record
Expand All @@ -445,6 +474,11 @@ export async function main(argv: readonly string[]): Promise<number> {
// `summary` reads records back; it runs nothing (`summary.ts`).
if (argv[0] === 'summary') return summaryMain(argv.slice(1));
const args = parseArgs(argv);
// `--schema-masking on` beside a shell that turns masking off says two things: refused before anything runs.
const maskingRefusal = schemaMaskingRefusal(args.schemaMasking);
if (maskingRefusal) throw new Error(maskingRefusal);
// The masking every booted app runs with, the shell's variable included: every record of the run states it.
const schemaMasking = roundSchemaMasking(args.schemaMasking);
const here = dirname(fileURLToPath(import.meta.url));
// The checkout, or the library root the published package carries (`library.ts`).
const { root: repo, checkout } = locateLibraryRoot(here);
Expand Down Expand Up @@ -507,6 +541,7 @@ export async function main(argv: readonly string[]): Promise<number> {
);
if (args.askRepeats !== undefined && args.askRepeats > 1) console.log(`ask repeats: each question turn asked ${args.askRepeats} times, operations once`);
if (promptChoice) console.log(`prompts: ${promptChoiceText(promptChoice)}`);
if (schemaMasking === 'off') console.log(`${schemaMaskingText('off')}${args.schemaMasking === undefined ? ' — set by the environment, not by --schema-masking' : ''}`);

// Built and packed once, before the first card: every scaffold of this run installs the same tarballs.
const workspace = args.packages === 'workspace' ? await prepareWorkspacePackages(repo, join(work, 'workspace-packages')) : undefined;
Expand All @@ -531,8 +566,8 @@ export async function main(argv: readonly string[]): Promise<number> {
os: (dir, a) => os(dir, a),
readArtifact,
namespace: readNamespace,
// Door mode's host serves the OAuth authorization server its client's token comes from.
boot: (dir, o) => bootDev(dir, undefined, o?.authoringDoor ? { OS_OIDC_PROVIDER_ENABLED: 'true' } : {}),
// Door mode's OAuth server, and a masking-off round's D8 opt-out (`bootEnv`).
boot: (dir, o) => bootDev(dir, undefined, bootEnv({ schemaMasking }, o?.authoringDoor)),
harness: (url) => new HttpApp({ baseUrl: url, adminEmail: ADMIN.email, adminPassword: ADMIN.password }),
};
const templateBytes = args.template ? readFileSync(args.template) : undefined;
Expand Down Expand Up @@ -562,7 +597,7 @@ export async function main(argv: readonly string[]): Promise<number> {
const packages: PackageSource = workspace ? workspace.source : { source: 'published', versions: [...publishedVersions].sort() };
// The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash.
const card = loadedCardStamp(loaded);
const record = withSuppliedTemplate(runRecord({ run: `${date}-scenario-${scenario.card.id}`, date, ...(framework ? { framework } : {}), packages, driver: info, runner: 'scenario-runner', evidenceDir: work, card }, cardRun), cardRun, supplied);
const record = withSuppliedTemplate(runRecord({ run: `${date}-scenario-${scenario.card.id}`, date, ...(framework ? { framework } : {}), packages, driver: info, runner: 'scenario-runner', evidenceDir: work, card, ...(schemaMasking === 'off' ? { schemaMasking: 'off' as const } : {}) }, cardRun), cardRun, supplied);
const file = join(outDir, `${date}-scenario-${scenario.card.id}.json`);
writeFileSync(file, JSON.stringify(record, null, 2));
console.log(renderScorecard(cardScorecard(cardRun, packages, card)));
Expand Down
1 change: 1 addition & 0 deletions packages/qa/scenarios/src/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './orchestrate.js';
export * from './packages.js';
export * from './project.js';
export * from './prompts.js';
export * from './schema-masking.js';
export * from './scorecard.js';
export * from './seed.js';
export * from './summary.js';
Expand Down
87 changes: 87 additions & 0 deletions packages/qa/scenarios/src/runner/schema-masking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* A masking-off round: the runner's one switch over the booted app's
* object-schema masking (ADR-0106 D8), and the stamp every record of such a
* round carries.
*
* By default every app the runner boots (`objectstack dev --fresh`,
* `bootDev` in `project.ts`) masks each caller's object schema to the fields
* that caller may read (ADR-0106). A card persona is a plain member, so a field
* the card withholds from it does not exist in its schema, and a question
* about that field is not the field-level-security question. That question
* needs a caller served the whole schema, or a deployment with masking off
* (D8): the persona then sees the field and asks for it, and a reply that the
* field is not visible to it passes while one that calls it blank or empty
* fails (the `withheld` grade, `gradePersonaRun`). `--schema-masking off`
* boots every app of the run with {@link OBJECT_SCHEMA_MASK_DISABLE_ENV} set,
* on the app's process only, and every record of the run says so
* (`env.schemaMasking: 'off'`); `summary` never sums such a run with a
* default one.
*
* The variable exported in the operator's shell turns masking off too: every
* child the runner spawns inherits the runner's own environment
* (`subscriptionOnlyEnv`, `driver.ts`), the booted app included. Such a run is
* a masking-off round, and it is recorded as one ({@link roundSchemaMasking}):
* the variable is read with the metadata plane's own predicate
* (`isObjectSchemaMaskingEnabled`), so the record says `off` exactly when the
* app reads the value as off, and a value it reads as masked (`0`, `false`,
* blank) stamps nothing. Recorded rather than refused, so no run the runner
* started before the flag is turned away, and the record states what ran.
* Only `--schema-masking on` beside a variable that turns masking off is
* refused ({@link schemaMaskingRefusal}): the two say opposite things.
*/

import { isObjectSchemaMaskingEnabled, OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core';

/** The values `--schema-masking` takes: `on` is the default (masked, nothing stamped), `off` the D8 opt-out. */
export const SCHEMA_MASKING_SETTINGS = ['on', 'off'] as const;
export type SchemaMasking = (typeof SCHEMA_MASKING_SETTINGS)[number];

type Env = Readonly<Record<string, string | undefined>>;

/** Does the operator's environment turn masking off, as the metadata plane reads {@link OBJECT_SCHEMA_MASK_DISABLE_ENV}. */
const environmentTurnsMaskingOff = (env: Env): boolean => !isObjectSchemaMaskingEnabled(undefined, { ...env });

/**
* Why a run may not start, or `undefined` when it may: `--schema-masking on`
* while the environment sets {@link OBJECT_SCHEMA_MASK_DISABLE_ENV} to a value
* that turns masking off, which every booted app would inherit. Pure over its
* inputs.
*/
export function schemaMaskingRefusal(flag: SchemaMasking | undefined, env: Env = process.env): string | undefined {
if (flag !== 'on' || !environmentTurnsMaskingOff(env)) return undefined;
return (
`--schema-masking on asks for masked apps, and \`${OBJECT_SCHEMA_MASK_DISABLE_ENV}\` in this environment turns ` +
`object-schema masking off (ADR-0106 D8) for every app the run boots. Unset it, or pass \`--schema-masking off\`.`
);
}

/**
* The schema masking a run's apps are booted with, which every record of the
* run states: `off` when `--schema-masking off` says so, or when no flag is
* given and the environment turns masking off
* ({@link OBJECT_SCHEMA_MASK_DISABLE_ENV}, read as the metadata plane reads
* it); `on` otherwise. Pure over its inputs.
*/
export function roundSchemaMasking(flag: SchemaMasking | undefined, env: Env = process.env): SchemaMasking {
if (flag !== undefined) return flag;
return environmentTurnsMaskingOff(env) ? 'off' : 'on';
}

/** What the booted app's environment gains: the D8 opt-out on a masking-off round, nothing otherwise. */
export function schemaMaskingHostEnv(masking: SchemaMasking | undefined): Record<string, string> {
return masking === 'off' ? { [OBJECT_SCHEMA_MASK_DISABLE_ENV]: '1' } : {};
}

/**
* A record's `env.schemaMasking` as `summary` and the run's banner state it:
* `schema masking: on` when absent (the default, and every record made before
* the flag), `schema masking: off (…)` for `off`, and any other value as it
* stands, so it is never read as either.
*/
export function schemaMaskingText(masking: string | undefined): string {
if (masking === undefined) return 'schema masking: on';
if (masking === 'off') return `schema masking: off (${OBJECT_SCHEMA_MASK_DISABLE_ENV}, ADR-0106 D8: every caller is served the whole object schema)`;
return `schema masking: ${masking}`;
}
Loading
Loading