@activate-core/test-forge 2.4.1 → 2.4.3

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.
package/README.md CHANGED
@@ -459,10 +459,12 @@ file, outside any test. `--no-scan` skips the look-up.
459
459
  `run` stops that area before running anything and prints the `npm i -D` to
460
460
  run, instead of every test failing as if the product were broken. A test that
461
461
  still hits it is reported as skipped with that reason. The same goes for the
462
- testkit's sign-in check: it uses an endpoint no journey tests, and when the
463
- server answers it with an error (a 5xx, a 429) the tests that need that role are
464
- reported as not started, with the status and the endpoint, not as failing their
465
- rules. `run` also says when
462
+ testkit's sign-in check: it uses an endpoint no journey tests, and when that
463
+ endpoint answers with anything but a 200 the testkit signs in afresh once and
464
+ carries on, so one broken endpoint never stops the suite. A run signs each role
465
+ in once, not once per test file. A testkit built before this that still stops on
466
+ the check has its failures reported as not started, with the status and the
467
+ endpoint, not as failing their rules. `run` also says when
466
468
  `TESTFORGE_KEY` is set but `dashboardUrl` is empty, so a run that will not be
467
469
  published is not a surprise.
468
470
 
@@ -55,7 +55,7 @@ export function buildDocCheckPrompt(doc, reference, excerpts, gaps, otherDocs =
55
55
  excerpts || '(none found)',
56
56
  `</source_excerpts>`,
57
57
  `<draft>`,
58
- doc,
58
+ withRuleIds(doc),
59
59
  `</draft>`,
60
60
  ].join('\n');
61
61
  }
@@ -72,6 +72,23 @@ export function parseFixes(out) {
72
72
  }
73
73
  const TAGGED = /\[(spec|baseline|observed)\]/i;
74
74
  const norm = (t) => t.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
75
+ /**
76
+ * The doc as the check sees it: every criterion starts with its id, also in a
77
+ * doc written before ids were part of the format, so a fix can name the rule
78
+ * it is about. The file itself is not changed.
79
+ */
80
+ export function withRuleIds(markdown) {
81
+ const memory = readRules(markdown);
82
+ const lines = markdown.split('\n');
83
+ const where = ruleLines(lines, memory);
84
+ for (const r of memory.rules) {
85
+ const i = where.get(r.id);
86
+ if (i === undefined || r.explicit)
87
+ continue;
88
+ lines[i] = lines[i].replace(/^(\s*(?:[-*]|\d+(?:\.\d+)*\.?)\s+)/, `$1${r.id} `);
89
+ }
90
+ return lines.join('\n');
91
+ }
75
92
  /** Line index of each rule's first line, by id. */
76
93
  function ruleLines(lines, memory) {
77
94
  const at = new Map();
@@ -122,11 +139,25 @@ export function applyFixes(markdown, fixes) {
122
139
  const where = ruleLines(lines, memory);
123
140
  const byRule = fixes.filter((f) => f.action !== 'add');
124
141
  const removed = new Set();
142
+ // A fix names its rule by id; one that quotes the rule's words instead is matched by them.
143
+ const resolve = (ref) => {
144
+ const t = ref.trim();
145
+ const id = /^R\d+$/i.test(t) ? t.toUpperCase() : (/^R\d+\b/i.exec(t)?.[0]?.toUpperCase());
146
+ if (id && ids.has(id))
147
+ return id;
148
+ const want = norm(t.replace(/^R\d+\s*/i, ''));
149
+ if (want.length < 15)
150
+ return undefined;
151
+ const hit = memory.rules.find((r) => r.tag && (norm(r.text.split('\n')[0]).startsWith(want) || want.startsWith(norm(r.text.split('\n')[0]))));
152
+ return hit?.id;
153
+ };
154
+ for (const f of byRule)
155
+ f.rule = resolve(f.rule ?? '') ?? f.rule;
125
156
  for (const f of byRule.sort((a, b) => (where.get(b.rule ?? '') ?? -1) - (where.get(a.rule ?? '') ?? -1))) {
126
- const id = (f.rule ?? '').trim().toUpperCase();
157
+ const id = (f.rule ?? '').trim();
127
158
  const i = where.get(id);
128
159
  if (!id || !ids.has(id) || i === undefined || removed.has(id)) {
129
- refused.push(`${f.action} ${id || '(no rule)'}: the doc has no such rule`);
160
+ refused.push(`${f.action} ${id.length > 40 ? `"${id.slice(0, 40)}…"` : id || '(no rule)'}: the doc has no such rule`);
130
161
  continue;
131
162
  }
132
163
  if (f.action === 'remove') {
@@ -223,10 +254,15 @@ export function withCoverage(markdown) {
223
254
  lines.splice(before >= 0 ? before : lines.length, 0, ...table);
224
255
  return lines.join('\n').replace(/\n{3,}/g, '\n\n');
225
256
  }
226
- /** The quoted words of a [spec] line's source, one entry per quote. */
257
+ /** Markdown links read as their text: "[a](a)" is "a" once. */
258
+ const flatLinks = (t) => t.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1');
259
+ /** The quoted words of a [spec] line's source, one entry per quote ("…" and \"…\" inside are kept). */
227
260
  function quotesOf(line) {
228
- const src = /\(source:[^"“]*["“]([\s\S]*?)["”]\s*\)/i.exec(line);
229
- return src ? [src[1]] : [];
261
+ const at = line.search(/\(source:/i);
262
+ if (at < 0)
263
+ return [];
264
+ const src = line.slice(at);
265
+ return [...src.matchAll(/["“]((?:\\.|[^"“”\\])*)["”]/g)].map((m) => flatLinks(m[1].replace(/\\"/g, '"')));
230
266
  }
231
267
  /**
232
268
  * A [spec] line whose quote is not in the reference is the drafter's reading,
@@ -234,7 +270,7 @@ function quotesOf(line) {
234
270
  * is checked piece by piece. Without a reference text nothing is checked.
235
271
  */
236
272
  export function verifySpecQuotes(markdown, reference) {
237
- const ref = ` ${norm(reference)} `;
273
+ const ref = ` ${norm(flatLinks(reference))} `;
238
274
  const retagged = [];
239
275
  if (!reference.trim())
240
276
  return { markdown, retagged };
@@ -250,7 +286,7 @@ export function verifySpecQuotes(markdown, reference) {
250
286
  const pieces = quotes.flatMap((q) => q.split(/…|\.\.\./)).map(norm).filter((p) => p.split(' ').length >= 3);
251
287
  if (pieces.every((p) => ref.includes(` ${p} `)))
252
288
  return line;
253
- retagged.push(/R\d+/.exec(line)?.[0] ?? line.trim().slice(0, 40));
289
+ retagged.push(/^\s*[-*]\s+(R\d+)\b/.exec(line)?.[1] ?? `"${line.replace(/^\s*[-*]\s+/, '').slice(0, 50)}…"`);
254
290
  return line.replace(/\[spec\]/gi, '[observed]');
255
291
  });
256
292
  return { markdown: out.join('\n'), retagged };
@@ -108,11 +108,15 @@ export const HARNESS_CONTRACT = [
108
108
  ` - That check uses the lightest authenticated endpoint the role can call,`,
109
109
  ` one that only says who is signed in, never a screen's data endpoint that`,
110
110
  ` a journey tests: a bug there would stop every test before it starts.`,
111
- ` - Only 401 or 403 means the token is refused: mint a new one once. Any other`,
112
- ` answer (a 5xx, a 429, no answer) is the server's, not the token's: do not`,
113
- ` mint again and do not retry per test. Remember it for the process and`,
114
- ` throw "testkit: token check <METHOD> <path> answered <status>" so every`,
115
- ` test that needs that role fails at once with the same reason.`,
111
+ ` - Only a 200 confirms a token. Any other answer (a refusal, a 5xx from a bug`,
112
+ ` or a local database behind the schema, a 429) leaves it unconfirmed: mint`,
113
+ ` a fresh one once through the real login and use it, so one broken endpoint`,
114
+ ` never stops every test. Never retry the check per test.`,
115
+ ` - Each test file loads the testkit anew: a token minted by another file of`,
116
+ ` the run in the last few minutes (cached with the time it was minted) is`,
117
+ ` used as it is, so a run logs each role in once, not once per file.`,
118
+ ` - When the login itself fails, throw "testkit: login as <identifier> failed`,
119
+ ` (<status>)": that, not the check, is what stops the role's tests.`,
116
120
  ` - Check connections by their live state and reopen them if closed; do not`,
117
121
  ` use "already set up" flags. Tests never disconnect the shared connection.`,
118
122
  `H5. Nothing destructive outside test data.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@activate-core/test-forge",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "AI-powered QA automation. Scans a project, drafts journey docs, and generates seeded Jest/Playwright tests. Works in any project, with any AI CLI.",
5
5
  "type": "module",
6
6
  "bin": {