Skip to content

Commit 8838fa4

Browse files
committed
feat(scenarios): record the shell's masking variable as a masking-off round, refuse --schema-masking on beside it
Claude-Session: https://claude.ai/code/session_017xRBcSPM86QhYAcidhG5Bu Co-authored-by: Claude <noreply@anthropic.com>
1 parent 68e450e commit 8838fa4

5 files changed

Lines changed: 89 additions & 41 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
feat(scenarios): `--schema-masking off` runs a recorded masking-off round, so the field-level-security question can be asked on the open cards
6+
7+
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.
8+
Metadata-protocol: none
9+
10+
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.

‎packages/qa/scenarios/README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,11 @@ the persona passes, one that calls it blank or empty fails (the `withheld` grade
305305
- **Never summed with a default round**: `summary` refuses a table whose runs differ in it, naming
306306
`schema masking` and the records on each side.
307307
- **The shell cannot turn it off unrecorded**: every child the runner spawns inherits its environment, so a run
308-
started with `OS_ALLOW_UNMASKED_OBJECT_METADATA` set (any value) and without `--schema-masking off` is refused
309-
before any card runs. Unset it, or pass the flag.
308+
started with `OS_ALLOW_UNMASKED_OBJECT_METADATA` set and no flag is a masking-off round, and is recorded as one: the
309+
runner reads the variable with the metadata plane's own predicate (`isObjectSchemaMaskingEnabled`), prints
310+
`schema masking: off (…) — set by the environment, not by --schema-masking` and stamps every record. A value the
311+
platform reads as masked (`0`, `false`, blank) stamps nothing. `--schema-masking on` beside a value that turns
312+
masking off is refused before any card runs.
310313
- A replay (`--driver recorded:F`) replays the answers the recording holds; the stamp states how this run booted its
311314
apps, not how the recorded turns' app was booted, so replay a masking-off recording with the flag.
312315

‎packages/qa/scenarios/src/runner/cli.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@
127127
* question; every record of the run says so
128128
* (`env.schemaMasking`), and `summary` never sums it
129129
* with a default run (default `on`: masked, nothing
130-
* stamped). The masking variable set in the
131-
* environment without this flag is refused before any
132-
* card runs
130+
* stamped). With no flag, the masking variable set in
131+
* the environment makes the run a masking-off round,
132+
* recorded as one; `on` beside it is refused
133133
*
134134
* `run-scenarios summary <record|dir>…` (`objectstack-scenarios summary`) reads
135135
* run records back instead and prints one author-model × ask-model table per
@@ -158,7 +158,7 @@ import { installedSpecVersion, PACKAGES_MODES, prepareWorkspacePackages, settleW
158158
import { bootDev, os, readArtifact, readNamespace, scaffold } from './project.js';
159159
import { PROMPT_LANGS, PROMPT_LENGTHS, promptChoiceText, promptLanguageRefusal, statedPromptChoice, type PromptChoice, type PromptLang, type PromptLength } from './prompts.js';
160160
import { rebaseScenario } from './run-date.js';
161-
import { SCHEMA_MASKING_SETTINGS, schemaMaskingHostEnv, schemaMaskingRefusal, schemaMaskingText, type SchemaMasking } from './schema-masking.js';
161+
import { roundSchemaMasking, SCHEMA_MASKING_SETTINGS, schemaMaskingHostEnv, schemaMaskingRefusal, schemaMaskingText, type SchemaMasking } from './schema-masking.js';
162162
import { cardScorecard, renderScorecard, runRecord, type CardStamp } from './scorecard.js';
163163
import { SUPPLIED_TEMPLATE_SOURCE, summaryMain, suppliedTemplateOf, type SuppliedTemplate } from './summary.js';
164164

@@ -225,7 +225,7 @@ export interface CliArgs {
225225
lang?: PromptLang;
226226
/** `--prompt`: the card prompt the build turn is given ({@link PromptChoice.prompt}); absent ⇒ `detailed`. */
227227
prompt?: PromptLength;
228-
/** `--schema-masking`: `off` boots every app of the run with object-schema masking off and stamps its records ({@link SchemaMasking}); absent or `on` ⇒ the default, masked. */
228+
/** `--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`). */
229229
schemaMasking?: SchemaMasking;
230230
}
231231

@@ -474,9 +474,11 @@ export async function main(argv: readonly string[]): Promise<number> {
474474
// `summary` reads records back; it runs nothing (`summary.ts`).
475475
if (argv[0] === 'summary') return summaryMain(argv.slice(1));
476476
const args = parseArgs(argv);
477-
// The masking variable inherited from the shell would reach every booted app unrecorded: refused before anything runs.
477+
// `--schema-masking on` beside a shell that turns masking off says two things: refused before anything runs.
478478
const maskingRefusal = schemaMaskingRefusal(args.schemaMasking);
479479
if (maskingRefusal) throw new Error(maskingRefusal);
480+
// The masking every booted app runs with, the shell's variable included: every record of the run states it.
481+
const schemaMasking = roundSchemaMasking(args.schemaMasking);
480482
const here = dirname(fileURLToPath(import.meta.url));
481483
// The checkout, or the library root the published package carries (`library.ts`).
482484
const { root: repo, checkout } = locateLibraryRoot(here);
@@ -539,7 +541,7 @@ export async function main(argv: readonly string[]): Promise<number> {
539541
);
540542
if (args.askRepeats !== undefined && args.askRepeats > 1) console.log(`ask repeats: each question turn asked ${args.askRepeats} times, operations once`);
541543
if (promptChoice) console.log(`prompts: ${promptChoiceText(promptChoice)}`);
542-
if (args.schemaMasking === 'off') console.log(schemaMaskingText('off'));
544+
if (schemaMasking === 'off') console.log(`${schemaMaskingText('off')}${args.schemaMasking === undefined ? ' — set by the environment, not by --schema-masking' : ''}`);
543545

544546
// Built and packed once, before the first card: every scaffold of this run installs the same tarballs.
545547
const workspace = args.packages === 'workspace' ? await prepareWorkspacePackages(repo, join(work, 'workspace-packages')) : undefined;
@@ -565,7 +567,7 @@ export async function main(argv: readonly string[]): Promise<number> {
565567
readArtifact,
566568
namespace: readNamespace,
567569
// Door mode's OAuth server, and a masking-off round's D8 opt-out (`bootEnv`).
568-
boot: (dir, o) => bootDev(dir, undefined, bootEnv(args, o?.authoringDoor)),
570+
boot: (dir, o) => bootDev(dir, undefined, bootEnv({ schemaMasking }, o?.authoringDoor)),
569571
harness: (url) => new HttpApp({ baseUrl: url, adminEmail: ADMIN.email, adminPassword: ADMIN.password }),
570572
};
571573
const templateBytes = args.template ? readFileSync(args.template) : undefined;
@@ -595,7 +597,7 @@ export async function main(argv: readonly string[]): Promise<number> {
595597
const packages: PackageSource = workspace ? workspace.source : { source: 'published', versions: [...publishedVersions].sort() };
596598
// The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash.
597599
const card = loadedCardStamp(loaded);
598-
const record = withSuppliedTemplate(runRecord({ run: `${date}-scenario-${scenario.card.id}`, date, ...(framework ? { framework } : {}), packages, driver: info, runner: 'scenario-runner', evidenceDir: work, card, ...(args.schemaMasking === 'off' ? { schemaMasking: 'off' as const } : {}) }, cardRun), cardRun, supplied);
600+
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);
599601
const file = join(outDir, `${date}-scenario-${scenario.card.id}.json`);
600602
writeFileSync(file, JSON.stringify(record, null, 2));
601603
console.log(renderScorecard(cardScorecard(cardRun, packages, card)));

‎packages/qa/scenarios/src/runner/schema-masking.ts‎

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,56 @@
1919
* (`env.schemaMasking: 'off'`); `summary` never sums such a run with a
2020
* default one.
2121
*
22-
* The variable reaches the app only through the flag. Every child the runner
23-
* spawns inherits the runner's own environment (`subscriptionOnlyEnv`,
24-
* `driver.ts`), so the variable exported in the operator's shell would turn
25-
* masking off with nothing in the record to say it. A run started so is
26-
* refused before any card runs ({@link schemaMaskingRefusal}), whatever the
27-
* value: how a value reads (`0`, `false`) is the booted app's version's
28-
* business, not the runner's. Refused rather than recorded, so that every
29-
* masking-off record is one an operator asked for by flag, and a default
30-
* round's record keeps its bytes.
22+
* The variable exported in the operator's shell turns masking off too: every
23+
* child the runner spawns inherits the runner's own environment
24+
* (`subscriptionOnlyEnv`, `driver.ts`), the booted app included. Such a run is
25+
* a masking-off round, and it is recorded as one ({@link roundSchemaMasking}):
26+
* the variable is read with the metadata plane's own predicate
27+
* (`isObjectSchemaMaskingEnabled`), so the record says `off` exactly when the
28+
* app reads the value as off, and a value it reads as masked (`0`, `false`,
29+
* blank) stamps nothing. Recorded rather than refused, so no run the runner
30+
* started before the flag is turned away, and the record states what ran.
31+
* Only `--schema-masking on` beside a variable that turns masking off is
32+
* refused ({@link schemaMaskingRefusal}): the two say opposite things.
3133
*/
3234

33-
import { OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core';
35+
import { isObjectSchemaMaskingEnabled, OBJECT_SCHEMA_MASK_DISABLE_ENV } from '@objectstack/metadata-core';
3436

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

41+
type Env = Readonly<Record<string, string | undefined>>;
42+
43+
/** Does the operator's environment turn masking off, as the metadata plane reads {@link OBJECT_SCHEMA_MASK_DISABLE_ENV}. */
44+
const environmentTurnsMaskingOff = (env: Env): boolean => !isObjectSchemaMaskingEnabled(undefined, { ...env });
45+
3946
/**
40-
* Why a run may not start, or `undefined` when it may: the operator's
41-
* environment sets {@link OBJECT_SCHEMA_MASK_DISABLE_ENV} and `--schema-masking`
42-
* is not `off`. Pure over its inputs.
47+
* Why a run may not start, or `undefined` when it may: `--schema-masking on`
48+
* while the environment sets {@link OBJECT_SCHEMA_MASK_DISABLE_ENV} to a value
49+
* that turns masking off, which every booted app would inherit. Pure over its
50+
* inputs.
4351
*/
44-
export function schemaMaskingRefusal(masking: SchemaMasking | undefined, env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {
45-
if (env[OBJECT_SCHEMA_MASK_DISABLE_ENV] === undefined || masking === 'off') return undefined;
52+
export function schemaMaskingRefusal(flag: SchemaMasking | undefined, env: Env = process.env): string | undefined {
53+
if (flag !== 'on' || !environmentTurnsMaskingOff(env)) return undefined;
4654
return (
47-
`\`${OBJECT_SCHEMA_MASK_DISABLE_ENV}\` is set in this environment, and every app the run boots inherits it: ` +
48-
`object-schema masking (ADR-0106 D8) could be off while the run's records say nothing of it. ` +
49-
`Unset it for a default round, or pass \`--schema-masking off\` for a masking-off round the records state.`
55+
`--schema-masking on asks for masked apps, and \`${OBJECT_SCHEMA_MASK_DISABLE_ENV}\` in this environment turns ` +
56+
`object-schema masking off (ADR-0106 D8) for every app the run boots. Unset it, or pass \`--schema-masking off\`.`
5057
);
5158
}
5259

60+
/**
61+
* The schema masking a run's apps are booted with, which every record of the
62+
* run states: `off` when `--schema-masking off` says so, or when no flag is
63+
* given and the environment turns masking off
64+
* ({@link OBJECT_SCHEMA_MASK_DISABLE_ENV}, read as the metadata plane reads
65+
* it); `on` otherwise. Pure over its inputs.
66+
*/
67+
export function roundSchemaMasking(flag: SchemaMasking | undefined, env: Env = process.env): SchemaMasking {
68+
if (flag !== undefined) return flag;
69+
return environmentTurnsMaskingOff(env) ? 'off' : 'on';
70+
}
71+
5372
/** What the booted app's environment gains: the D8 opt-out on a masking-off round, nothing otherwise. */
5473
export function schemaMaskingHostEnv(masking: SchemaMasking | undefined): Record<string, string> {
5574
return masking === 'off' ? { [OBJECT_SCHEMA_MASK_DISABLE_ENV]: '1' } : {};

‎packages/qa/scenarios/test/runner/masking-off-ask-round.test.ts‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* A masking-off ask round (`--schema-masking off`, `src/runner/schema-masking.ts`):
55
* the field-level-security question asked on the open cards. The flag boots
66
* the app with object-schema masking off (ADR-0106 D8) and nowhere else, the
7-
* round's records say so, `summary` never sums such a round with a default
8-
* one, and the masking variable inherited from the shell is refused before
9-
* any card runs. A default round's record keeps its bytes.
7+
* round's records say so, and `summary` never sums such a round with a default
8+
* one. The masking variable inherited from the shell makes a masking-off round
9+
* too, recorded as one (read as the metadata plane reads it); `--schema-masking
10+
* on` beside it is refused before any card runs. A default round's record
11+
* keeps its bytes.
1012
*
1113
* The grade itself is the one every round uses (`gradeCardAnswer`, as
1214
* `orchestrate.ts` calls it): asked as `employee`, from whom `travel_expense`
@@ -28,7 +30,7 @@ import { formatRefusal, loadScenarioFile, readCapabilityAreas, type LoadedScenar
2830
import { bootEnv, main, parseArgs } from '../../src/runner/cli.js';
2931
import { namespacedScenario } from '../../src/runner/namespace.js';
3032
import { hiddenValues } from '../../src/runner/orchestrate.js';
31-
import { schemaMaskingHostEnv, schemaMaskingRefusal, schemaMaskingText } from '../../src/runner/schema-masking.js';
33+
import { roundSchemaMasking, schemaMaskingHostEnv, schemaMaskingRefusal, schemaMaskingText } from '../../src/runner/schema-masking.js';
3234
import { runRecord } from '../../src/runner/scorecard.js';
3335
import { readSummaryRecords, renderSummaryTable, summaryMain, summaryTables } from '../../src/runner/summary.js';
3436
import { gradeCardAnswer } from '../../src/score/index.js';
@@ -53,15 +55,27 @@ describe('--schema-masking: the flag, and the variable the shell carries', () =>
5355
expect(OBJECT_SCHEMA_MASK_DISABLE_ENV).toBe('OS_ALLOW_UNMASKED_OBJECT_METADATA');
5456
});
5557

56-
it('refuses the variable set without the flag, whatever its value, and allows it with `off`', () => {
57-
for (const value of ['1', 'true', '0', 'false', '']) {
58+
it('records the variable the shell sets as a masking-off round, read as the metadata plane reads it', () => {
59+
for (const value of ['1', 'true', 'yes']) {
5860
const env = { [OBJECT_SCHEMA_MASK_DISABLE_ENV]: value };
59-
expect(schemaMaskingRefusal(undefined, env)).toContain(`\`${OBJECT_SCHEMA_MASK_DISABLE_ENV}\` is set in this environment`);
60-
expect(schemaMaskingRefusal('on', env)).toContain('pass `--schema-masking off`');
61+
expect(roundSchemaMasking(undefined, env)).toBe('off');
62+
expect(roundSchemaMasking('off', env)).toBe('off');
63+
expect(schemaMaskingRefusal(undefined, env)).toBeUndefined();
6164
expect(schemaMaskingRefusal('off', env)).toBeUndefined();
65+
// `on` beside a variable that turns masking off says two things.
66+
expect(schemaMaskingRefusal('on', env)).toBe(
67+
`--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\`.`,
68+
);
69+
}
70+
// A value the metadata plane reads as masked stamps nothing, and leaves `on` standing.
71+
for (const value of ['0', 'false', 'FALSE', '', ' ']) {
72+
const env = { [OBJECT_SCHEMA_MASK_DISABLE_ENV]: value };
73+
expect(roundSchemaMasking(undefined, env)).toBe('on');
74+
expect(schemaMaskingRefusal('on', env)).toBeUndefined();
6275
}
76+
expect(roundSchemaMasking(undefined, {})).toBe('on');
77+
expect(roundSchemaMasking('off', {})).toBe('off');
6378
expect(schemaMaskingRefusal(undefined, {})).toBeUndefined();
64-
expect(schemaMaskingRefusal('off', {})).toBeUndefined();
6579
});
6680

6781
it('gives the booted app the opt-out on a masking-off round only, beside door mode’s OAuth server', () => {
@@ -85,13 +99,13 @@ describe('--schema-masking: the flag, and the variable the shell carries', () =>
8599
else process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV] = saved;
86100
});
87101

88-
it('refuses a run the shell turned masking off for, before it makes a directory or loads a card', async () => {
102+
it('refuses `--schema-masking on` in a shell that turned masking off, before it makes a directory or loads a card', async () => {
89103
process.env[OBJECT_SCHEMA_MASK_DISABLE_ENV] = '1';
90104
const root = tmp();
91105
const out = join(root, 'runs');
92106
const work = join(root, 'work');
93-
await expect(main(['--driver', 'recorded:/nonexistent.json', '--out', out, '--work', work])).rejects.toThrow(
94-
`\`${OBJECT_SCHEMA_MASK_DISABLE_ENV}\` is set in this environment, and every app the run boots inherits it`,
107+
await expect(main(['--schema-masking', 'on', '--driver', 'recorded:/nonexistent.json', '--out', out, '--work', work])).rejects.toThrow(
108+
`--schema-masking on asks for masked apps, and \`${OBJECT_SCHEMA_MASK_DISABLE_ENV}\` in this environment turns object-schema masking off`,
95109
);
96110
expect(existsSync(out)).toBe(false);
97111
expect(existsSync(work)).toBe(false);

0 commit comments

Comments
 (0)