@kurvball/rehearse 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,7 @@ export interface Affected {
14
14
  by: 'all' | 'graph' | 'packages';
15
15
  graph: string | null;
16
16
  files: string[];
17
+ inert: string[];
17
18
  said: string | null;
18
19
  reached: Reached[];
19
20
  }
@@ -79,6 +79,11 @@ export async function affected(m, checkout, given, scenarios) {
79
79
  const files = [
80
80
  ...new Set(given.map((f) => toPosix(path.relative(checkout, path.resolve(checkout, f))))),
81
81
  ].sort();
82
+ const neverInert = new Set([
83
+ toPosix(path.relative(checkout, m.file)),
84
+ ...scenarios.map((s) => toPosix(path.relative(checkout, path.resolve(s.from === 'manifest' ? m.dir : checkout, s.file)))),
85
+ ]);
86
+ const inert = files.filter((f) => !neverInert.has(f) && matches(f, m.affected.inert));
82
87
  const pkgs = workspaceOf(checkout);
83
88
  const graph = graphCommand(m, checkout);
84
89
  let said = null;
@@ -119,7 +124,7 @@ export async function affected(m, checkout, given, scenarios) {
119
124
  why.add(`it covers ${r}${via}`);
120
125
  const p = pkgOf(r);
121
126
  if (!p) {
122
- if (!graphHolds && (!through || through === r))
127
+ if (!graphHolds && (!through || through === r) && !inert.includes(r))
123
128
  why.add(`${r} is outside every package, so it reaches every scenario`);
124
129
  return;
125
130
  }
@@ -148,15 +153,20 @@ export async function affected(m, checkout, given, scenarios) {
148
153
  reached.push({ scenario: s, reachedBy: [...why] });
149
154
  }
150
155
  const unknown = graphRead?.unknown.filter((f) => files.includes(f)) ?? [];
156
+ const howItReached = graphRead
157
+ ? unknown.length
158
+ ? `The graph doesn't hold ${unknown.join(', ')}: for ${unknown.length === 1 ? 'it' : 'those'}, Rehearse took the package and the packages that depend on it.`
159
+ : null
160
+ : [said, jsOnly].filter(Boolean).join(' ') || null;
161
+ const inertSaid = inert.length
162
+ ? `${inert.length === 1 ? `${inert[0]} is` : `${inert.length} files (${inert.join(', ')}) are`} outside every package but change no behaviour, so ${inert.length === 1 ? 'it reaches' : 'they reach'} only what covers ${inert.length === 1 ? 'it' : 'them'} or what the graph says (affected.inert).`
163
+ : null;
151
164
  return {
152
165
  by: graphRead ? 'graph' : 'packages',
153
166
  graph: graphRead ? graph : null,
154
167
  files,
155
- said: graphRead
156
- ? unknown.length
157
- ? `The graph doesn't hold ${unknown.join(', ')}: for ${unknown.length === 1 ? 'it' : 'those'}, Rehearse took the package and the packages that depend on it.`
158
- : null
159
- : [said, jsOnly].filter(Boolean).join(' ') || null,
168
+ inert,
169
+ said: [howItReached, inertSaid].filter(Boolean).join(' ') || null,
160
170
  reached,
161
171
  };
162
172
  }
@@ -24,7 +24,7 @@ export function comparisonText(c) {
24
24
  lines.push('', `${VERDICT_WORDS[verdict]}:`);
25
25
  for (const s of these) {
26
26
  const where = `${s.scenario.file}${s.scenario.line ? `:${s.scenario.line}` : ''}`;
27
- lines.push(` ${s.scenario.name} (${where})${s.said === 'announced' && s.why ? ` — announced: ${s.why}` : s.said === 'edited' ? ' — its definition was edited' : ''}`);
27
+ lines.push(` ${s.scenario.name} (${where})${s.said === 'announced' && s.why ? ` — announced: ${s.why}` : s.said === 'edited' ? ' — its definition was edited' : s.verdict === 'unsaid' && s.edited ? ' — its definition was edited too, but it is a contract: announce what changed' : ''}`);
28
28
  for (const d of s.differences.slice(0, 4))
29
29
  lines.push(` ${d.path}: ${d.base} → ${d.head}${d.count > 1 ? ` (${d.count} places)` : ''}`);
30
30
  if (s.differences.length > 4)
@@ -43,7 +43,7 @@ export function comparisonText(c) {
43
43
  lines.push(` ${b.path} — in ${b.scenarios.length} scenario${b.scenarios.length === 1 ? '' : 's'}`);
44
44
  }
45
45
  if (c.gone.length)
46
- lines.push('', 'gone from the head:', ...c.gone.map((g) => ` ${g.name} (${g.file})`));
46
+ lines.push('', 'gone from the head:', ...c.gone.map((g) => ` ${g.name} (${g.file})${g.contract ? ' — a contract: announce it if it was meant' : ''}`));
47
47
  if (c.notRun.length)
48
48
  lines.push('', 'not run:', ...c.notRun.map((n) => ` ${n.scenario.name} on the ${n.side} (${n.step}): ${n.says}`));
49
49
  if (c.announcedUnchanged.length)
@@ -55,6 +55,7 @@ export const list = {
55
55
  by: reach.by,
56
56
  graph: reach.graph,
57
57
  files: reach.files,
58
+ ...(reach.inert.length && { inert: reach.inert }),
58
59
  said: reach.said,
59
60
  scenarios: reach.reached.map((r) => row(r.scenario, r.reachedBy)),
60
61
  refused: read.refused,
@@ -1,5 +1,5 @@
1
1
  import { type Failure } from '../kinds/index.ts';
2
- import type { Manifest } from '../manifest/index.ts';
2
+ import { type Manifest } from '../manifest/index.ts';
3
3
  import { type CheckoutInfo, type Observation } from '../run/index.ts';
4
4
  import { type ScenarioRef } from '../scenarios/index.ts';
5
5
  import type { Difference } from './diff.ts';
@@ -5,6 +5,7 @@ import { affected } from '../affected/index.js';
5
5
  import { RehearseError, errorText } from '../errors.js';
6
6
  import { checkoutFor, infoOf, commitOf, gitOr, topOf } from '../git/index.js';
7
7
  import { runnerOf } from '../kinds/index.js';
8
+ import { loadManifest } from '../manifest/index.js';
8
9
  import { cached, cacheKeyOf, groupsOf, keep, runSideSharing, slotsFor, } from '../run/index.js';
9
10
  import { readScenarios, refOf, globToRegExp, } from '../scenarios/index.js';
10
11
  import { runningServices, stateDir } from '../services/index.js';
@@ -84,6 +85,17 @@ function bothSidesMayRunAtOnce(m, base, head) {
84
85
  runningServices(m.dir).every((r) => onlyTheseTwo.has(path.resolve(r.checkout))));
85
86
  }
86
87
  const latestComparisonFile = (m, everyScenario) => path.join(stateDir(m.dir), 'compare', everyScenario ? 'latest.json' : 'latest-partial.json');
88
+ function setAsideChangedOnTheBase(m, base) {
89
+ const inTheRepository = path.relative(topOf(m.dir) ?? m.dir, m.file);
90
+ if (inTheRepository.startsWith('..') || path.isAbsolute(inTheRepository))
91
+ return false;
92
+ try {
93
+ return (JSON.stringify(loadManifest(path.join(base, inTheRepository)).setAside) !== JSON.stringify(m.setAside));
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
87
99
  export async function compare(m, o) {
88
100
  const begun = Date.now();
89
101
  const parallel = o.parallel ?? 1;
@@ -125,6 +137,8 @@ export async function compare(m, o) {
125
137
  const baseCommit = commitOf(base.path);
126
138
  const files = baseCommit ? changedFiles(head.path, baseCommit) : [];
127
139
  const reach = await affected(m, head.path, files, headScenarios);
140
+ if (reach.inert.length && reach.said)
141
+ o.progress(reach.said);
128
142
  const ids = new Set(reach.reached.map((r) => r.scenario.id));
129
143
  headScenarios = headScenarios.filter((s) => ids.has(s.id));
130
144
  const baseReach = await affected(m, base.path, files, baseScenarios);
@@ -209,6 +223,7 @@ export async function compare(m, o) {
209
223
  notRunOf('base', baseRun.notRun);
210
224
  notRunOf('head', headRun.notRun);
211
225
  const notRunIds = new Set(out.notRun.map((n) => n.scenario.id));
226
+ const rulesChanged = setAsideChangedOnTheBase(m, base.path);
212
227
  const baseById = new Map(baseScenarios.map((s) => [s.id, s]));
213
228
  const allBase = new Map(baseRead.scenarios.map((s) => [s.id, s]));
214
229
  const standins = new Map();
@@ -237,9 +252,18 @@ export async function compare(m, o) {
237
252
  },
238
253
  ];
239
254
  const baseScenario = baseById.get(s.id) ?? allBase.get(s.id);
240
- const edited = s.from === 'checkout' && baseScenario !== undefined && baseScenario.definition !== s.definition;
255
+ const aContract = s.contract === true || baseScenario?.contract === true;
256
+ const edited = (s.from === 'checkout' && baseScenario !== undefined && baseScenario.definition !== s.definition) ||
257
+ (aContract && rulesChanged);
241
258
  const announcement = announcementFor(s.id, announced);
242
- const said = announcement ? 'announced' : edited ? 'edited' : null;
259
+ const said = announcement ? 'announced' : edited && !aContract ? 'edited' : null;
260
+ if (aContract && edited && differences.length === 0)
261
+ differences.push({
262
+ path: rulesChanged ? 'set-aside rules in rehearse.yaml' : 'its definition',
263
+ base: 'as on the base',
264
+ head: 'edited',
265
+ count: 1,
266
+ });
243
267
  const changed = differences.length > 0;
244
268
  const failsOnHead = !h.ok;
245
269
  const failsOnBase = b ? !b.ok : false;
@@ -267,6 +291,7 @@ export async function compare(m, o) {
267
291
  out.counts.failsOnBoth += 1;
268
292
  }
269
293
  out.gone = baseScenarios.filter((s) => !headIds.has(s.id)).map(refOf);
294
+ const goneContractsUnsaid = out.gone.filter((g) => g.contract === true && !announcementFor(g.id, announced));
270
295
  out.counts.gone = out.gone.length;
271
296
  out.counts.notRun = new Set(out.notRun.map((n) => n.scenario.id)).size;
272
297
  for (const a of announced) {
@@ -300,7 +325,8 @@ export async function compare(m, o) {
300
325
  out.head.ok &&
301
326
  out.counts.notRun === 0 &&
302
327
  out.counts.fails === 0 &&
303
- out.counts.unsaid === 0;
328
+ out.counts.unsaid === 0 &&
329
+ goneContractsUnsaid.length === 0;
304
330
  out.ms = Date.now() - begun;
305
331
  mkdirSync(dir, { recursive: true });
306
332
  writeFileSync(path.join(dir, 'comparison.json'), `${JSON.stringify(out, null, 2)}\n`);
@@ -15,6 +15,7 @@ export interface FileSpec {
15
15
  person?: string;
16
16
  services?: string[];
17
17
  covers?: string[];
18
+ contract?: boolean;
18
19
  input?: {
19
20
  file?: string;
20
21
  command?: string;
@@ -43,6 +43,7 @@ registerReader({
43
43
  person: spec.person ?? m.defaults.person,
44
44
  service: spec.services?.[0] ?? null,
45
45
  covers: [...f.covers, ...(spec.covers ?? [])],
46
+ ...(spec.contract === true && { contract: true }),
46
47
  spec,
47
48
  },
48
49
  ];
@@ -1,5 +1,5 @@
1
1
  export { fill, fillEnv } from './fill.ts';
2
2
  export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.ts';
3
- export { findManifest, hashOf, loadManifest, MANIFEST_FILE, manifestFrom } from './load.ts';
3
+ export { findManifest, hashOf, INERT_BY_DEFAULT, loadManifest, MANIFEST_FILE, manifestFrom } from './load.ts';
4
4
  export { KIND_BLOCK, KINDS, type Kind, type Manifest, type PathEntry, type Person, type Real, type Service, type Standin, type World, } from './types.ts';
5
5
  export { readYaml } from './yaml.ts';
@@ -1,5 +1,5 @@
1
1
  export { fill, fillEnv } from './fill.js';
2
2
  export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.js';
3
- export { findManifest, hashOf, loadManifest, MANIFEST_FILE, manifestFrom } from './load.js';
3
+ export { findManifest, hashOf, INERT_BY_DEFAULT, loadManifest, MANIFEST_FILE, manifestFrom } from './load.js';
4
4
  export { KIND_BLOCK, KINDS, } from './types.js';
5
5
  export { readYaml } from './yaml.js';
@@ -1,4 +1,5 @@
1
1
  import type { Manifest } from './types.ts';
2
+ export declare const INERT_BY_DEFAULT: readonly string[];
2
3
  export declare const MANIFEST_FILE = "rehearse.yaml";
3
4
  export declare const MANIFEST_VARIABLE = "REHEARSE_MANIFEST";
4
5
  export declare function findManifest(cwd: string, given: string | null, env?: NodeJS.ProcessEnv): string;
@@ -4,6 +4,19 @@ import path from 'node:path';
4
4
  import { RehearseError } from '../errors.js';
5
5
  import { validate } from '../schema.js';
6
6
  import { readYaml } from './yaml.js';
7
+ export const INERT_BY_DEFAULT = [
8
+ '.changeset/*.md',
9
+ '.github/workflows/**',
10
+ '.github/ISSUE_TEMPLATE/**',
11
+ '.github/PULL_REQUEST_TEMPLATE*',
12
+ '.github/CODEOWNERS',
13
+ '.github/dependabot.yml',
14
+ '.vscode/**',
15
+ '.idea/**',
16
+ '*.md',
17
+ 'LICENSE',
18
+ 'LICENSE.*',
19
+ ];
7
20
  export const MANIFEST_FILE = 'rehearse.yaml';
8
21
  export const MANIFEST_VARIABLE = 'REHEARSE_MANIFEST';
9
22
  const isFile = (file) => {
@@ -213,7 +226,7 @@ export function manifestFrom(text, file) {
213
226
  values: raw.setAside?.values ?? [],
214
227
  keep: raw.setAside?.keep ?? [],
215
228
  },
216
- affected: { graph: raw.affected?.graph ?? null },
229
+ affected: { graph: raw.affected?.graph ?? null, inert: raw.affected?.inert ?? [...INERT_BY_DEFAULT] },
217
230
  budget: { services: raw.budget?.services ?? 1, checkouts: raw.budget?.checkouts ?? 3 },
218
231
  lineOf: (at, key) => read.lineOf(at, key),
219
232
  };
@@ -40,6 +40,7 @@ export interface RawManifest {
40
40
  setAside?: SetAsideRules;
41
41
  affected?: {
42
42
  graph?: string;
43
+ inert?: string[];
43
44
  };
44
45
  budget?: {
45
46
  services?: number;
@@ -246,6 +247,7 @@ export interface Manifest {
246
247
  setAside: Required<SetAsideRules>;
247
248
  affected: {
248
249
  graph: string | null;
250
+ inert: string[];
249
251
  };
250
252
  budget: {
251
253
  services: number;
@@ -14,6 +14,7 @@ export interface Scenario {
14
14
  person: string | null;
15
15
  service: string | null;
16
16
  covers: string[];
17
+ contract?: boolean;
17
18
  spec: unknown;
18
19
  }
19
20
  export interface Refused {
@@ -30,5 +31,6 @@ export interface ScenarioRef {
30
31
  area: string;
31
32
  from: 'checkout' | 'manifest';
32
33
  definition: string;
34
+ contract?: true;
33
35
  }
34
36
  export declare const refOf: (s: Scenario) => ScenarioRef;
@@ -7,4 +7,5 @@ export const refOf = (s) => ({
7
7
  area: s.area,
8
8
  from: s.from,
9
9
  definition: s.definition,
10
+ ...(s.contract === true && { contract: true }),
10
11
  });
package/llms.txt CHANGED
@@ -29,7 +29,7 @@
29
29
 
30
30
  ## Verdicts
31
31
 
32
- - same: as on the base. said: changed and said so (announced, or its own definition edited; announced wins). unsaid: changed without saying so. new: not on the base. fails: fails on the head (failsOnBase: it fails on the base too, so not this change's doing).
32
+ - same: as on the base. said: changed and said so (announced, or its own definition edited, unless it is a file scenario with contract: true; announced wins). unsaid: changed without saying so. new: not on the base. fails: fails on the head (failsOnBase: it fails on the base too, so not this change's doing).
33
33
  - Ids, times and opaque tokens are set aside before comparing; arrays keep their order unless a scenario says unordered; a comparison counts what it set aside.
34
34
  - A change announces what it expects to change in .rehearse/announce.yaml beside rehearse.yaml (schema announce): changes: [{scenario: <id or glob>, why: <one line>}].
35
35
  - The base's observations are cached by commit under .rehearse/cache, so each base commit runs once; scenarios that share services in a world are cached and run as a group; --fresh runs again.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurvball/rehearse",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Rehearse a change before it ships: bring the product up, sign in as named people, start from named worlds, and compare any scenario on the base and on the head.",
5
5
  "homepage": "https://rehearse.kurvball.ca/",
6
6
  "repository": {
@@ -54,6 +54,10 @@
54
54
  "definition": {
55
55
  "description": "A hash of the scenario's parsed definition. It changes when the scenario itself is edited.",
56
56
  "type": "string"
57
+ },
58
+ "contract": {
59
+ "description": "True for a file scenario marked contract: true. A contract gone from the head needs an announcement.",
60
+ "const": true
57
61
  }
58
62
  }
59
63
  },
@@ -114,7 +114,7 @@
114
114
  "type": "boolean"
115
115
  },
116
116
  "said": {
117
- "description": "announced when the change announced it (this wins, since it carries why), else edited when its own definition changed, else null.",
117
+ "description": "announced when the change announced it (this wins, since it carries why), else edited when its own definition changed (never for a contract, which only an announcement says), else null.",
118
118
  "enum": ["announced", "edited", null]
119
119
  },
120
120
  "why": {
@@ -33,6 +33,10 @@
33
33
  "type": "string"
34
34
  }
35
35
  },
36
+ "contract": {
37
+ "description": "A contract, such as a command's JSON: editing the scenario doesn't say its output changed on purpose, so a change still needs an announcement, such as a rehearse: line in a changeset.",
38
+ "type": "boolean"
39
+ },
36
40
  "input": {
37
41
  "description": "The input: a file beside this one, or a command that writes {{input}}.",
38
42
  "type": "object",
@@ -21,6 +21,13 @@
21
21
  "type": "string"
22
22
  }
23
23
  },
24
+ "inert": {
25
+ "description": "With --affected, the touched files outside every package that change no behaviour (affected.inert in rehearse.yaml), such as a changeset: they don't reach every scenario. Left out when there are none.",
26
+ "type": "array",
27
+ "items": {
28
+ "type": "string"
29
+ }
30
+ },
24
31
  "said": {
25
32
  "description": "Anything the reader should know, such as why Ashlar wasn't used.",
26
33
  "type": ["string", "null"]
@@ -106,6 +106,11 @@
106
106
  "graph": {
107
107
  "description": "A command that prints the dependents of the files appended to it, as schema/v1/dependents.schema.json says. By default, Ashlar's when Ashlar is present.",
108
108
  "type": "string"
109
+ },
110
+ "inert": {
111
+ "description": "Globs over files outside every package that change no behaviour, such as changesets and CI workflows: they don't reach every scenario, but still reach what covers them, what the import graph says, and their own package. The manifest and scenario files are never inert. By default .changeset/*.md, .github/workflows/**, .github/ISSUE_TEMPLATE/**, .github/PULL_REQUEST_TEMPLATE*, .github/CODEOWNERS, .github/dependabot.yml, .vscode/**, .idea/**, *.md at the root, LICENSE and LICENSE.*; [] makes every file count",
112
+ "type": "array",
113
+ "items": { "type": "string" }
109
114
  }
110
115
  },
111
116
  "additionalProperties": false