@activate-core/test-forge 2.1.0 → 2.1.1

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.
@@ -9,7 +9,11 @@
9
9
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
10
10
  import { join, relative, resolve } from 'node:path';
11
11
  const CODE = /\.(tsx?|jsx?|mjs|cjs|vue|svelte|php|py|rb|go)$/;
12
- const SKIP_DIR = /^(node_modules|\.next|dist|build|coverage|vendor|storage|\.git|tests?|__tests__|__mocks__|test-artifacts|testforge|generated-tests)$/;
12
+ const SKIP_DIR = /^(node_modules|\.next|dist|build|coverage|vendor|storage|public|\.git|tests?|__tests__|__mocks__|test-artifacts|testforge|generated-tests)$/;
13
+ /** Where a package keeps its code: src/ when it has one, else the package itself (Laravel's app/, a flat repo). */
14
+ export function sourceRoot(base = '.') {
15
+ return existsSync(join(base, 'src')) ? join(base, 'src') : base;
16
+ }
13
17
  const FILE_REF = /((?:[\w.-]+\/)+[\w.-]+\.(?:tsx?|jsx?|mjs|cjs|vue|svelte|php|py|rb|go))(?::(\d+)(?:[-–](\d+))?)?/g;
14
18
  const QUOTED = /"([^"\n]{4,60})"/g;
15
19
  /** Words in a control's name that name no component in particular. */
@@ -108,10 +108,22 @@ export function buildLeanReviewPrompt(doc, section, excerpts, otherDocs) {
108
108
  export function enforceSpecSources(markdown) {
109
109
  let inFence = false;
110
110
  let retagged = 0;
111
- const lines = markdown.split('\n').map((line) => {
111
+ const all = markdown.split('\n');
112
+ // A rule's source may sit on a later line of its own block (after its
113
+ // steps), up to the next rule or heading.
114
+ const sourcedBelow = (i) => {
115
+ for (let j = i + 1; j < all.length && j <= i + 30; j++) {
116
+ if (/^#{1,6}\s/.test(all[j]) || /\[(?:spec|baseline|observed)\]/i.test(all[j]))
117
+ return false;
118
+ if (HAS_SOURCE.test(all[j]))
119
+ return true;
120
+ }
121
+ return false;
122
+ };
123
+ const lines = all.map((line, i) => {
112
124
  if (/^\s*```/.test(line))
113
125
  inFence = !inFence;
114
- if (inFence || !/\[spec\]/i.test(line) || HAS_SOURCE.test(line))
126
+ if (inFence || !/\[spec\]/i.test(line) || HAS_SOURCE.test(line) || sourcedBelow(i))
115
127
  return line;
116
128
  retagged += 1;
117
129
  return line.replace(/\[spec\]/gi, '[observed]');
@@ -14,7 +14,7 @@ import { findMarkdownFiles } from '../find-files.js';
14
14
  import { notAJourneyDoc, parseJourney } from '../docs/parser.js';
15
15
  import { loadConfig, testDirForType } from '../project/config.js';
16
16
  import { matchesJourney } from './plan-cache.js';
17
- import { sourceText } from '../docs/excerpts.js';
17
+ import { sourceRoot, sourceText } from '../docs/excerpts.js';
18
18
  import { checkReadiness, shownTexts, testFilesIn } from '../run/readiness.js';
19
19
  function journeys(docsDir, only) {
20
20
  const config = loadConfig();
@@ -52,7 +52,7 @@ function rawSource(roots) {
52
52
  return parts.join('\n');
53
53
  }
54
54
  export function sourceRoots() {
55
- return ['src', ...(loadConfig().relatedDirs ?? [])];
55
+ return [sourceRoot(), ...(loadConfig().relatedDirs ?? [])];
56
56
  }
57
57
  export function bindJourneys(opts = {}) {
58
58
  const roots = sourceRoots();
@@ -20,7 +20,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
20
20
  import { dirname, relative } from 'node:path';
21
21
  import { loadConfig, splitCommand, withNoTools, withReferenceTools } from '../project/config.js';
22
22
  import { readRules, ruleIndex } from './journey-memory.js';
23
- import { sourceExcerpts } from '../docs/excerpts.js';
23
+ import { sourceExcerpts, sourceRoot } from '../docs/excerpts.js';
24
24
  import { runWithStdin, DEFECT_MARK, FINDING_MARK } from './ai-generator.js';
25
25
  import { aiUnavailableReason, noteAiFailure, noteAiSuccess, waitForAi } from './ai-session.js';
26
26
  const IMPACTS = ['blocker', 'major', 'minor'];
@@ -349,7 +349,7 @@ checkpoint) {
349
349
  const noTools = !decisions.link;
350
350
  const tools = decisions.link ? withReferenceTools : withNoTools;
351
351
  const { program, args } = tools(splitCommand(config.aiCommand));
352
- const roots = ['src', ...(config.relatedDirs ?? [])];
352
+ const roots = [sourceRoot(), ...(config.relatedDirs ?? [])];
353
353
  const ask = io?.ask ?? ((prompt) => runWithStdin(program, args, prompt, config.aiTimeoutMs));
354
354
  const wait = io?.wait ?? (() => ((config.waitForLimit ?? true) ? waitForAi(config) : Promise.resolve(false)));
355
355
  const out = [];
@@ -82,6 +82,20 @@ export function readRules(markdown) {
82
82
  }
83
83
  if (mode !== 'rules')
84
84
  continue;
85
+ // A numbered rule ("1.4 [spec] …") owns everything below it — its steps,
86
+ // its notes, its "(source: …)" line — up to the next rule or heading.
87
+ const numbered = /^\s*\d+(?:\.\d+)*\.?\s+(\[(?:spec|baseline|observed)\][\s\S]*)$/i.exec(line);
88
+ if (numbered) {
89
+ close();
90
+ const tag = (TAG.exec(numbered[1])?.[1] ?? '');
91
+ current = { rule: { id: `R${rules.length + 1}`, section, group, tag, text: numbered[1], controls: [] }, indent: Number.MAX_SAFE_INTEGER, owns: true };
92
+ rules.push(current.rule);
93
+ continue;
94
+ }
95
+ if (current?.owns && !TAG.test(line)) {
96
+ current.rule.text += `\n${line}`;
97
+ continue;
98
+ }
85
99
  const bullet = /^(\s*)[-*]\s+(.*)$/.exec(line);
86
100
  if (bullet) {
87
101
  const indent = bullet[1].length;
@@ -41,7 +41,7 @@ import { factsSlice, helperApi, journeySlice, readRules, recordWritten, saveMemo
41
41
  import { loadSourceChoice } from '../docs/source-of-truth.js';
42
42
  import { alignRules, describeDiff, loadMemory } from './doc-diff.js';
43
43
  import { updateJourney } from './update-journey.js';
44
- import { sourceText } from '../docs/excerpts.js';
44
+ import { sourceRoot, sourceText } from '../docs/excerpts.js';
45
45
  import { isSyntaxValid, checkTestGates, duplicatedHelpers, unbalancedAt } from '../gates/validate.js';
46
46
  import { installedModules, transportHint, projectSelectors } from '../project/detect.js';
47
47
  import { harnessInfo, generateHarnessAsync, harnessIsCurrent, stampHarness, generateHarness, playwrightConfig, globalSetupContent, fixturesDoc, jestConfig, jestSetupContent, } from './harness.js';
@@ -428,7 +428,7 @@ export async function runGenerate(docsDir, useAI = true, force = false, only, ar
428
428
  // labels are checked against it before the test is run.
429
429
  let knownTexts;
430
430
  const appTexts = () => framework === 'playwright'
431
- ? (knownTexts ??= `${sourceText([join(packageRoot(areaDir), 'src'), ...(config.relatedDirs ?? [])])} ${markdown.toLowerCase().replace(/\s+/g, ' ')}`)
431
+ ? (knownTexts ??= `${sourceText([sourceRoot(packageRoot(areaDir)), ...(config.relatedDirs ?? [])])} ${markdown.toLowerCase().replace(/\s+/g, ' ')}`)
432
432
  : undefined;
433
433
  const genGate = (content, filePath) => testGate(content) ??
434
434
  checkTestGates(content, ext, {
@@ -553,7 +553,7 @@ export async function runGenerate(docsDir, useAI = true, force = false, only, ar
553
553
  const aligned = memory;
554
554
  const diff = docDiff;
555
555
  console.log(` ${journey.id}: doc changed — ${describeDiff(diff)}`);
556
- const facts = notBuilt ? undefined : (await groundJourney(journey, hash, 'src', markdown, true)) ?? undefined;
556
+ const facts = notBuilt ? undefined : (await groundJourney(journey, hash, sourceRoot(), markdown, true)) ?? undefined;
557
557
  const up = await updateJourney({
558
558
  journey, memory: aligned, diff, plan: prevPlan, tested, helpers, facts, harnessPath, transport,
559
559
  pathOf: (f) => join(testDir, `${flat ? `${journey.id}-${f.slug}` : f.slug}${ext}`),
@@ -611,7 +611,7 @@ export async function runGenerate(docsDir, useAI = true, force = false, only, ar
611
611
  // on first use: re-checking an existing suite costs no grounding at all.
612
612
  let groundingP;
613
613
  const grounding = () => (groundingP ??= useAI && !notBuilt
614
- ? groundJourney(journey, hash, 'src', markdown).then((g) => g ?? undefined)
614
+ ? groundJourney(journey, hash, sourceRoot(), markdown).then((g) => g ?? undefined)
615
615
  : Promise.resolve(undefined));
616
616
  const staleRemoved = cleanStaleFiles(testDir, journey.id, ext, flat, plannedSlugs, prevSlugs);
617
617
  if (staleRemoved.length) {
@@ -13,7 +13,7 @@
13
13
  * playwright.config live), with config.envFile merged into the env.
14
14
  */
15
15
  import { checkReadiness, testFilesIn } from './readiness.js';
16
- import { sourceText } from '../docs/excerpts.js';
16
+ import { sourceRoot, sourceText } from '../docs/excerpts.js';
17
17
  import { spawnSync } from 'node:child_process';
18
18
  import { existsSync } from 'node:fs';
19
19
  import { join, dirname, resolve, relative } from 'node:path';
@@ -136,7 +136,7 @@ export function runTests(opts = {}) {
136
136
  if (framework === 'playwright' && !opts.all) {
137
137
  const scope = opts.journey && existsSync(join(testDir, opts.journey)) ? join(testDir, opts.journey) : testDir;
138
138
  const files = testFilesIn(scope).filter((f) => !opts.journey || f.includes(opts.journey));
139
- const roots = ['src', ...(config.relatedDirs ?? [])];
139
+ const roots = [sourceRoot(), ...(config.relatedDirs ?? [])];
140
140
  const states = checkReadiness(files, sourceText(roots), () => [], [root]);
141
141
  const held = states.filter((s) => s.state === 'not-built');
142
142
  if (held.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@activate-core/test-forge",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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": {