@sun-asterisk/sungen 3.2.19 → 3.2.20
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/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +6 -0
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/exporters/matrix/build.d.ts.map +1 -1
- package/dist/exporters/matrix/build.js +9 -1
- package/dist/exporters/matrix/build.js.map +1 -1
- package/dist/exporters/test-data-resolver.d.ts +15 -0
- package/dist/exporters/test-data-resolver.d.ts.map +1 -1
- package/dist/exporters/test-data-resolver.js +34 -1
- package/dist/exporters/test-data-resolver.js.map +1 -1
- package/dist/generators/test-generator/adapters/adapter-interface.d.ts +1 -0
- package/dist/generators/test-generator/adapters/adapter-interface.d.ts.map +1 -1
- package/dist/generators/test-generator/adapters/appium/appium-adapter.d.ts +1 -0
- package/dist/generators/test-generator/adapters/appium/appium-adapter.d.ts.map +1 -1
- package/dist/generators/test-generator/adapters/appium/appium-adapter.js.map +1 -1
- package/dist/generators/test-generator/adapters/playwright/playwright-adapter.d.ts +1 -0
- package/dist/generators/test-generator/adapters/playwright/playwright-adapter.d.ts.map +1 -1
- package/dist/generators/test-generator/adapters/playwright/playwright-adapter.js.map +1 -1
- package/dist/generators/test-generator/adapters/playwright/templates/imports.hbs +3 -0
- package/dist/generators/test-generator/adapters/playwright/templates/steps/navigation/navigation.hbs +4 -0
- package/dist/generators/test-generator/adapters/playwright/templates/steps/partials/url-assertion.hbs +11 -6
- package/dist/generators/test-generator/code-generator.d.ts.map +1 -1
- package/dist/generators/test-generator/code-generator.js +9 -1
- package/dist/generators/test-generator/code-generator.js.map +1 -1
- package/dist/generators/test-generator/diagnostics.d.ts +10 -1
- package/dist/generators/test-generator/diagnostics.d.ts.map +1 -1
- package/dist/generators/test-generator/diagnostics.js +9 -0
- package/dist/generators/test-generator/diagnostics.js.map +1 -1
- package/dist/generators/test-generator/step-mapper.d.ts +24 -0
- package/dist/generators/test-generator/step-mapper.d.ts.map +1 -1
- package/dist/generators/test-generator/step-mapper.js +53 -0
- package/dist/generators/test-generator/step-mapper.js.map +1 -1
- package/dist/generators/test-generator/template-engine.d.ts +1 -0
- package/dist/generators/test-generator/template-engine.d.ts.map +1 -1
- package/dist/generators/test-generator/template-engine.js +1 -1
- package/dist/generators/test-generator/template-engine.js.map +1 -1
- package/dist/generators/test-generator/utils/data-resolver.d.ts +11 -0
- package/dist/generators/test-generator/utils/data-resolver.d.ts.map +1 -1
- package/dist/generators/test-generator/utils/data-resolver.js +20 -0
- package/dist/generators/test-generator/utils/data-resolver.js.map +1 -1
- package/dist/harness/script-check.d.ts.map +1 -1
- package/dist/harness/script-check.js +9 -1
- package/dist/harness/script-check.js.map +1 -1
- package/dist/harness/secret-scan.d.ts.map +1 -1
- package/dist/harness/secret-scan.js +13 -1
- package/dist/harness/secret-scan.js.map +1 -1
- package/dist/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +6 -0
- package/dist/orchestrator/templates/ai-src/skills/sungen-error-mapping/SKILL.md +4 -0
- package/dist/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +33 -5
- package/dist/orchestrator/templates/ai-src/skills/sungen-selector-fix/SKILL.md +1 -1
- package/dist/orchestrator/templates/ai-src/skills/sungen-selector-keys/SKILL.md +6 -3
- package/dist/orchestrator/templates/specs-url-assert.d.ts +67 -0
- package/dist/orchestrator/templates/specs-url-assert.d.ts.map +1 -0
- package/dist/orchestrator/templates/specs-url-assert.js +121 -0
- package/dist/orchestrator/templates/specs-url-assert.js.map +1 -0
- package/dist/orchestrator/templates/specs-url-assert.ts +134 -0
- package/package.json +3 -3
- package/src/cli/commands/generate.ts +5 -0
- package/src/exporters/matrix/build.ts +9 -1
- package/src/exporters/test-data-resolver.ts +34 -1
- package/src/generators/test-generator/adapters/adapter-interface.ts +1 -1
- package/src/generators/test-generator/adapters/appium/appium-adapter.ts +1 -1
- package/src/generators/test-generator/adapters/playwright/playwright-adapter.ts +1 -1
- package/src/generators/test-generator/adapters/playwright/templates/imports.hbs +3 -0
- package/src/generators/test-generator/adapters/playwright/templates/steps/navigation/navigation.hbs +4 -0
- package/src/generators/test-generator/adapters/playwright/templates/steps/partials/url-assertion.hbs +11 -6
- package/src/generators/test-generator/code-generator.ts +10 -2
- package/src/generators/test-generator/diagnostics.ts +10 -1
- package/src/generators/test-generator/step-mapper.ts +54 -0
- package/src/generators/test-generator/template-engine.ts +2 -2
- package/src/generators/test-generator/utils/data-resolver.ts +19 -0
- package/src/harness/script-check.ts +9 -1
- package/src/harness/secret-scan.ts +12 -1
- package/src/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +6 -0
- package/src/orchestrator/templates/ai-src/skills/sungen-error-mapping/SKILL.md +4 -0
- package/src/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +33 -5
- package/src/orchestrator/templates/ai-src/skills/sungen-selector-fix/SKILL.md +1 -1
- package/src/orchestrator/templates/ai-src/skills/sungen-selector-keys/SKILL.md +6 -3
- package/src/orchestrator/templates/specs-url-assert.ts +134 -0
|
@@ -141,10 +141,43 @@ function truncate(s: string, max: number): string {
|
|
|
141
141
|
* test-data map (or resolving to empty) is left as the literal `{{var}}` — never blanked.
|
|
142
142
|
*/
|
|
143
143
|
export function substituteTestDataVars(text: string, testData: Record<string, string>): string {
|
|
144
|
-
|
|
144
|
+
const out = text.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (m, key: string) => {
|
|
145
145
|
const v = testData[key];
|
|
146
146
|
return v === undefined || v === null || v === '' ? m : String(v);
|
|
147
147
|
});
|
|
148
|
+
// A substituted value may itself carry a dynamic token ("Award-{{$timestamp}}").
|
|
149
|
+
// String.replace never re-scans its own replacement, so name them afterwards.
|
|
150
|
+
return renderDynamicTokens(out);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Give the documented dynamic vars (`{{$timestamp}}`, `{{$uuid}}`,
|
|
155
|
+
* `{{$random:min:max}}`, `{{$date}}`, `{{$datetime}}`) a form a tester can act on.
|
|
156
|
+
*
|
|
157
|
+
* These are resolved by TestDataLoader at execution time, never from
|
|
158
|
+
* test-data.yaml — so at export time they have no static value, exactly like a
|
|
159
|
+
* value the run captures (`remember … as {{v}}` → `the captured v`). Left raw,
|
|
160
|
+
* the token ships into the deliverable and the matrix's Gate D rejects the
|
|
161
|
+
* whole export. Named, the tester reads what to type: any value of that shape,
|
|
162
|
+
* uniqueness being the whole point.
|
|
163
|
+
*
|
|
164
|
+
* An UNKNOWN `{{$foo}}` stays literal on purpose — the runtime resolver also
|
|
165
|
+
* leaves it raw, so it is an authoring typo and must keep failing Gate D.
|
|
166
|
+
*/
|
|
167
|
+
export function renderDynamicTokens(text: string): string {
|
|
168
|
+
return text.replace(/\{\{\s*\$(\w+)(?::([^}]*))?\s*\}\}/g, (m, name: string, args?: string) => {
|
|
169
|
+
switch (name) {
|
|
170
|
+
case 'timestamp': return '<unique timestamp>';
|
|
171
|
+
case 'uuid': return '<unique id>';
|
|
172
|
+
case 'random': {
|
|
173
|
+
const [min, max] = (args || '1:9999').split(':');
|
|
174
|
+
return `<random ${min}-${max}>`;
|
|
175
|
+
}
|
|
176
|
+
case 'date': return "<today's date>";
|
|
177
|
+
case 'datetime': return '<current date-time>';
|
|
178
|
+
default: return m;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
148
181
|
}
|
|
149
182
|
|
|
150
183
|
/**
|
|
@@ -67,7 +67,7 @@ export interface TestGeneratorAdapter {
|
|
|
67
67
|
// Template rendering methods
|
|
68
68
|
renderTestFile(data: TestFileData): string;
|
|
69
69
|
renderScenario(data: ScenarioData): string;
|
|
70
|
-
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean ; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean }): string;
|
|
70
|
+
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean ; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean; urlAssertImports?: string }): string;
|
|
71
71
|
renderBeforeEach(data: { steps: Array<{ comment?: string; code: string }> }): string;
|
|
72
72
|
renderBeforeAll(data: { steps: Array<{ comment?: string; code: string }> }): string;
|
|
73
73
|
renderAfterEach(data: { steps: Array<{ comment?: string; code: string }> }): string;
|
|
@@ -31,7 +31,7 @@ export class AppiumAdapter implements TestGeneratorAdapter {
|
|
|
31
31
|
return this.templateEngine.renderScenario(data);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean }): string {
|
|
34
|
+
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean; urlAssertImports?: string }): string {
|
|
35
35
|
return this.templateEngine.renderImports(options);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -26,7 +26,7 @@ export class PlaywrightAdapter implements TestGeneratorAdapter {
|
|
|
26
26
|
return this.templateEngine.renderScenario(data);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean ; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean }): string {
|
|
29
|
+
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean ; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean; urlAssertImports?: string }): string {
|
|
30
30
|
return this.templateEngine.renderImports(options);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -12,6 +12,9 @@ import { api } from '{{basePath}}/api';
|
|
|
12
12
|
{{#if needsMock}}
|
|
13
13
|
import { mock } from '{{basePath}}/mock';
|
|
14
14
|
{{/if}}
|
|
15
|
+
{{#if urlAssertImports}}
|
|
16
|
+
import { {{urlAssertImports}} } from '{{basePath}}/url-assert';
|
|
17
|
+
{{/if}}
|
|
15
18
|
|
|
16
19
|
// This file is auto-generated from Gherkin feature files
|
|
17
20
|
// DO NOT EDIT MANUALLY - changes will be overwritten
|
package/src/generators/test-generator/adapters/playwright/templates/steps/navigation/navigation.hbs
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
{{#if query}}
|
|
2
|
+
await page.goto(joinPath('{{#if baseURL}}{{baseURL}}{{/if}}', '{{path}}', '{{escapeQuotes query}}'), { waitUntil: 'load' });
|
|
3
|
+
{{else}}
|
|
1
4
|
await page.goto('{{#if baseURL}}{{baseURL}}{{/if}}{{path}}', { waitUntil: 'load' });
|
|
5
|
+
{{/if}}
|
|
2
6
|
await page.waitForLoadState('domcontentloaded');
|
package/src/generators/test-generator/adapters/playwright/templates/steps/partials/url-assertion.hbs
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
Both used to carry their own copy and drifted apart: `see [X] page` wildcarded a dynamic
|
|
3
3
|
`:id` segment but silently dropped `with {{v}}`, while `is on [X] page` asserted the query
|
|
4
4
|
but escaped `:id` literally into a regex that can never match. One partial, one behaviour.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
|
|
6
|
+
The predicate itself lives in specs/url-assert.ts (template: specs-url-assert.ts) — read it
|
|
7
|
+
for the semantics. It is a runtime helper rather than an inline lambda so that correcting
|
|
8
|
+
what "the URL matches" MEANS is a runtime patch, not a regenerate-the-world breaking change
|
|
9
|
+
for every suite in the field.
|
|
10
|
+
|
|
11
|
+
Only `pathRegex` is the generator's business: it alone knows the page selector's value and
|
|
12
|
+
its `:id` wildcards, and it is pre-escaped by pathToRegexSource. `\/?$` normalises a
|
|
13
|
+
trailing slash so `/vi/search/` does not read as a different page. The declared value stays
|
|
14
|
+
a plain string literal so the runtime-data marker pass can rewrite it to testData.get(…). --}}
|
|
15
|
+
await expect(page).toHaveURL(urlMatches({ pathname: /^{{pathRegex}}\/?$/{{#if query}}, dataRef: '{{escapeQuotes dataRef}}', declared: '{{escapeQuotes query}}'{{/if}} }));
|
|
@@ -316,11 +316,19 @@ export class CodeGenerator {
|
|
|
316
316
|
for (const h of capabilityRegistry.get(id)?.runtimeHelpers ?? []) this.syncGeneratedHelper(outputDir, h.file, h.template);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
const imports = this.adapter.renderImports({ runtimeData: this.options.runtimeData, basePath, needsCleanupImport, needsDb, needsApi, needsMock });
|
|
320
|
-
|
|
321
319
|
// Generate test code (async now to support AI mapping)
|
|
322
320
|
const testCode = await this.generateTestCode(feature);
|
|
323
321
|
|
|
322
|
+
// `url-assert` is imported from what the body actually emitted, not from an active capability:
|
|
323
|
+
// page assertions belong to the DEFAULT ui capability, so a capability flag would import the
|
|
324
|
+
// helper into every UI spec — including the many that touch no URL at all. Hence the body is
|
|
325
|
+
// rendered BEFORE the imports. Importing exactly the names used keeps the import honest; the
|
|
326
|
+
// helper file itself is synced only when something needs it (an api-only unit carries none).
|
|
327
|
+
const urlAssertImports = ['urlMatches', 'joinPath'].filter((n) => testCode.includes(`${n}(`)).join(', ');
|
|
328
|
+
if (urlAssertImports) this.syncGeneratedHelper(outputDir, 'url-assert.ts', 'specs-url-assert.ts');
|
|
329
|
+
|
|
330
|
+
const imports = this.adapter.renderImports({ runtimeData: this.options.runtimeData, basePath, needsCleanupImport, needsDb, needsApi, needsMock, urlAssertImports });
|
|
331
|
+
|
|
324
332
|
// Combine and collapse any runs of 3+ newlines down to 2 (one blank line max)
|
|
325
333
|
const raw = `${imports}\n\n${testCode}`;
|
|
326
334
|
let code = raw.replace(/\n{3,}/g, '\n\n');
|
|
@@ -26,12 +26,21 @@
|
|
|
26
26
|
* SG-W012 — a mock-install step AFTER a navigation step in the same block: page.route()
|
|
27
27
|
* registered after goto() misses every request fired during page load — move
|
|
28
28
|
* the install before the navigation (or into Background)
|
|
29
|
+
* SG-W013 — a page assertion whose path came from a FALLBACK, not from a `type: page` selector
|
|
30
|
+
* entry: the `[Ref]` did not resolve (or resolved to a non-page entry), so the step
|
|
31
|
+
* asserts the feature's own path (or `/<ref>/`) instead of the page it names. The
|
|
32
|
+
* assertion is anchored, so this is now a test that cannot pass rather than one that
|
|
33
|
+
* always passed — either way it is not asserting what it reads as
|
|
34
|
+
* SG-W014 — `[X] page with {{v}}` where the value carries no query and no fragment: there is
|
|
35
|
+
* nothing for the query half to assert, so the step checks the PATH only. Not an
|
|
36
|
+
* error (the value may legitimately vary per environment), but the step asserts
|
|
37
|
+
* strictly less than it appears to
|
|
29
38
|
*
|
|
30
39
|
* Diagnostics never block generation by themselves; `sungen generate --strict`
|
|
31
40
|
* turns any collected diagnostic into a non-zero exit.
|
|
32
41
|
*/
|
|
33
42
|
|
|
34
|
-
export type DiagnosticCode = 'SG-W001' | 'SG-W002' | 'SG-W003' | 'SG-W005' | 'SG-W006' | 'SG-W007' | 'SG-W008' | 'SG-W009' | 'SG-W010' | 'SG-W011' | 'SG-W012';
|
|
43
|
+
export type DiagnosticCode = 'SG-W001' | 'SG-W002' | 'SG-W003' | 'SG-W005' | 'SG-W006' | 'SG-W007' | 'SG-W008' | 'SG-W009' | 'SG-W010' | 'SG-W011' | 'SG-W012' | 'SG-W013' | 'SG-W014';
|
|
35
44
|
|
|
36
45
|
export interface Diagnostic {
|
|
37
46
|
code: DiagnosticCode;
|
|
@@ -333,6 +333,8 @@ export class StepMapper {
|
|
|
333
333
|
console.log(` ✓ Pattern matched: ${step.text.substring(0, 50)}...`);
|
|
334
334
|
}
|
|
335
335
|
this.checkDataRefConsumed(step, mappedStep);
|
|
336
|
+
this.checkPageAssertionFallback(step, mappedStep);
|
|
337
|
+
this.checkDeclaredUrlHasNoQuery(step, mappedStep);
|
|
336
338
|
return mappedStep;
|
|
337
339
|
}
|
|
338
340
|
|
|
@@ -400,6 +402,58 @@ export class StepMapper {
|
|
|
400
402
|
return expr || undefined;
|
|
401
403
|
}
|
|
402
404
|
|
|
405
|
+
/**
|
|
406
|
+
* SG-W013 — a page assertion whose path came from a fallback rather than from a `type: page`
|
|
407
|
+
* selector entry. Both resolvers degrade quietly when `[Ref]` does not resolve: `see [X] page`
|
|
408
|
+
* falls back to the feature's own path, `is on [X] page` to `/<ref>/`. Before the assertion was
|
|
409
|
+
* anchored that produced a test which always PASSED; anchored, it produces one that can never
|
|
410
|
+
* pass. Neither is the assertion the author wrote, and nothing said so.
|
|
411
|
+
*
|
|
412
|
+
* Detected here rather than in the resolver on purpose: `MappedStep` carries only
|
|
413
|
+
* `{code, comment, imports}`, and the resolvers live in the driver packages while the collector
|
|
414
|
+
* lives in core. Re-asking the SAME resolver the step-mapper already owns costs three lines and
|
|
415
|
+
* duplicates no logic — the alternative is widening the adapter contract for every driver.
|
|
416
|
+
*/
|
|
417
|
+
private checkPageAssertionFallback(step: ParsedStep, mapped: MappedStep): void {
|
|
418
|
+
if (!this.diagnostics || !step.selectorRef || step.elementType !== 'page') return;
|
|
419
|
+
if (!(mapped.code || '').includes('urlMatches(')) return;
|
|
420
|
+
let resolvedAsPage = false;
|
|
421
|
+
try {
|
|
422
|
+
const resolved = this.selectorResolver.resolveSelector(
|
|
423
|
+
step.selectorRef, this.featureName, step.elementType, step.nth
|
|
424
|
+
);
|
|
425
|
+
resolvedAsPage = resolved.selectorType === 'page' && !!resolved.value;
|
|
426
|
+
} catch {
|
|
427
|
+
resolvedAsPage = false;
|
|
428
|
+
}
|
|
429
|
+
if (resolvedAsPage) return;
|
|
430
|
+
this.diagnostics.add('SG-W013',
|
|
431
|
+
`page assertion for "[${step.selectorRef}]" has no "type: page" selector entry, so it asserts a FALLBACK path — the anchored assertion cannot match the real URL. Declare the page, e.g. "${step.selectorRef.toLowerCase()}:\\n type: page\\n value: '/your/path'"`,
|
|
432
|
+
{ feature: this.featureName, step: step.text });
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* SG-W014 — `[X] page with {{v}}` where the value carries neither a query nor a fragment, so the
|
|
437
|
+
* query half of the assertion has nothing to check and the step asserts the PATH only.
|
|
438
|
+
*
|
|
439
|
+
* Deliberately a warning, not an error, and deliberately judged on the BASE test-data value: an
|
|
440
|
+
* env overlay can supply a query the base file lacks, so failing generation here would block a
|
|
441
|
+
* suite over data that is fine at run time. But it must not be silent either — asserting less
|
|
442
|
+
* than the step reads as is exactly the false-positive class this assertion exists to remove.
|
|
443
|
+
* Distinct from SG-W002: there the value is DROPPED, here it is used and found to hold no query.
|
|
444
|
+
*/
|
|
445
|
+
private checkDeclaredUrlHasNoQuery(step: ParsedStep, mapped: MappedStep): void {
|
|
446
|
+
if (!this.diagnostics || !step.dataRef || step.elementType !== 'page') return;
|
|
447
|
+
if (!(mapped.code || '').includes('urlMatches(')) return;
|
|
448
|
+
// The base value, never resolveData(): in runtime mode that returns the marker, which carries
|
|
449
|
+
// no query by construction — the diagnostic would then fire on every single step.
|
|
450
|
+
const value = this.dataResolver.peekBaseValue(step.dataRef, this.featureName);
|
|
451
|
+
if (value == null || /[?#]/.test(value)) return;
|
|
452
|
+
this.diagnostics.add('SG-W014',
|
|
453
|
+
`{{${step.dataRef}}} = "${value}" carries no query and no fragment, so this page assertion checks the PATH only. Pass a value like "?q=…" (or drop the "with" and let the step assert a bare page).`,
|
|
454
|
+
{ feature: this.featureName, step: step.text });
|
|
455
|
+
}
|
|
456
|
+
|
|
403
457
|
/**
|
|
404
458
|
* SG-W002 — a step carried a parsed {{dataRef}} but the matched pattern's generated
|
|
405
459
|
* code never uses it (neither the runtime marker, the ${ref} fallback, nor the
|
|
@@ -277,8 +277,8 @@ export class TemplateEngine {
|
|
|
277
277
|
this.baseContext = { ...this.persistentContext };
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean ; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean }): string {
|
|
281
|
-
return this.render('imports', { runtimeData: options?.runtimeData, basePath: options?.basePath || '..', isParallel: options?.isParallel, needsCleanupImport: options?.needsCleanupImport, needsDb: options?.needsDb, needsApi: options?.needsApi, needsMock: options?.needsMock });
|
|
280
|
+
renderImports(options?: { runtimeData?: boolean; basePath?: string; isParallel?: boolean; needsCleanupImport?: boolean ; needsDb?: boolean; needsApi?: boolean; needsMock?: boolean; urlAssertImports?: string }): string {
|
|
281
|
+
return this.render('imports', { runtimeData: options?.runtimeData, basePath: options?.basePath || '..', isParallel: options?.isParallel, needsCleanupImport: options?.needsCleanupImport, needsDb: options?.needsDb, needsApi: options?.needsApi, needsMock: options?.needsMock, urlAssertImports: options?.urlAssertImports });
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
renderTestFile(data: {
|
|
@@ -64,6 +64,25 @@ export class DataResolver {
|
|
|
64
64
|
return this.resolveValue(dataRef, featureName);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The value as the BASE test-data file spells it, whatever the mode — for compile-time
|
|
69
|
+
* diagnostics that must judge the value itself, not the `__SUNGEN_TD$…$__` marker that
|
|
70
|
+
* `resolveData` returns in runtime mode.
|
|
71
|
+
*
|
|
72
|
+
* Returns undefined rather than throwing when the ref cannot be read (unknown path, or a
|
|
73
|
+
* captured var that only exists at runtime): a diagnostic must never break generation. Callers
|
|
74
|
+
* must treat the result as the base value only — an env overlay can change it at run time, so
|
|
75
|
+
* anything said about it belongs in a warning, never a gate.
|
|
76
|
+
*/
|
|
77
|
+
peekBaseValue(dataRef: string, featureName?: string): string | undefined {
|
|
78
|
+
if (this.capturedVars.has(dataRef)) return undefined;
|
|
79
|
+
try {
|
|
80
|
+
return this.resolveValue(dataRef, featureName);
|
|
81
|
+
} catch {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
67
86
|
private resolveValue(dataRef: string, featureName?: string): string {
|
|
68
87
|
const { fileName, valuePath } = this.parseDataRef(dataRef, featureName);
|
|
69
88
|
const data = this.loadDataFile(fileName);
|
|
@@ -57,7 +57,15 @@ export function extractTestBlocks(specSrc: string): { title: string; body: strin
|
|
|
57
57
|
return blocks;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
// A line counts as executable code when it interacts with the page/assertions/data,
|
|
61
|
+
// assigns, OR is a standalone call expression (`mock.setPassthrough(page);`,
|
|
62
|
+
// `driver.enable(...)`). The call branch is what keeps capability helpers from
|
|
63
|
+
// reading as hollow: a sync void call after its step comment matched none of the
|
|
64
|
+
// original alternatives (no await/expect/testData, `page` only as a bare argument,
|
|
65
|
+
// no `=`), so @mock:passthrough scenarios were flagged BYPASS (field report) — on
|
|
66
|
+
// sungen's own mock-route golden fixture, no less. Comment lines are step markers
|
|
67
|
+
// (never inside a scanned region), so `identifier(` cannot false-match non-code.
|
|
68
|
+
const CODE_LINE = /\b(await|expect|testData|page\.)\b|=\s*[^=]|[\w$]\s*\(/;
|
|
61
69
|
|
|
62
70
|
/**
|
|
63
71
|
* Faithfulness / anti-bypass: a non-@manual test that performs actions but proves
|
|
@@ -27,7 +27,18 @@ function scanText(text: string, file: string): SecretHit[] {
|
|
|
27
27
|
}
|
|
28
28
|
const m = raw.match(SECRET_KEY);
|
|
29
29
|
if (m) {
|
|
30
|
-
|
|
30
|
+
// Take only the FIRST scalar after the key. The old `(.+)$` capture swallowed
|
|
31
|
+
// the rest of the line, so in an inline-map @cases row
|
|
32
|
+
// - { …, password: "${QA_X}", expected_status: 201 }
|
|
33
|
+
// the "value" included `, expected_status: 201 }` — whose digits + length
|
|
34
|
+
// pushed EVERY such row over the threshold regardless of the actual value
|
|
35
|
+
// (field report: ${QA_*} refs and a deliberate wrong_password all warned).
|
|
36
|
+
const tail = m[2].trim();
|
|
37
|
+
const quoted = tail.match(/^(["'])((?:\\.|(?!\1).)*)\1/);
|
|
38
|
+
const val = (quoted ? quoted[2] : tail.split(/[,}\s]/, 1)[0]).trim();
|
|
39
|
+
// A ${VAR} env ref IS the recommended practice (.env.qa overlays) — never
|
|
40
|
+
// warn on it, or the gate teaches users the opposite of the convention.
|
|
41
|
+
if (/^\$\{[A-Za-z_][A-Za-z0-9_]*\}$/.test(val)) return;
|
|
31
42
|
// Long, high-entropy-ish, not an obvious placeholder/test value.
|
|
32
43
|
if (val.length >= 20 && !PLACEHOLDERish.test(raw) && /[A-Za-z]/.test(val) && /[0-9]/.test(val)) {
|
|
33
44
|
hits.push({ file, line, reason: `secret-named key "${m[1]}" with a long literal value` });
|
|
@@ -99,6 +99,12 @@ scheme (`SEC-123`, `PER-345`, `MS-HP-001`) is addressed the same way, and the ca
|
|
|
99
99
|
exist in test-data, so Gate D does not ask for them: the capture step renders as an instruction
|
|
100
100
|
(`Note the X text for later (as "v")`) and later references read `the captured v`.
|
|
101
101
|
|
|
102
|
+
**Dynamic vars**: `{{$timestamp}}`, `{{$uuid}}`, `{{$random:min:max}}`, `{{$date}}`, `{{$datetime}}`
|
|
103
|
+
are resolved by TestDataLoader at execution time — including when nested inside a test-data value
|
|
104
|
+
(`seed: "Summary intro {{$timestamp}}"`). They have no static value to print, so the report names
|
|
105
|
+
them instead: `<unique timestamp>`, `<unique id>`, `<random 1-100>`, `<today's date>`,
|
|
106
|
+
`<current date-time>`. An unknown `{{$foo}}` is left raw on purpose — it is a typo and Gate D says so.
|
|
107
|
+
|
|
102
108
|
**Data fidelity**: invisible test data is made visible, never normalized — `''` → `(empty)`,
|
|
103
109
|
whitespace-only → `(5 spaces)`, padded → `" value "` quoted verbatim. A trim/collapse here would
|
|
104
110
|
silently break the whitespace tests it describes.
|
|
@@ -95,6 +95,10 @@ needs any of these, it is a **finding for QA** — surface it in the run summary
|
|
|
95
95
|
| `SG-W008` | `@manual` scenario incomplete in either direction: (a) HAS Gherkin steps but NO `Then` — a dangling `When` is invalid Gherkin, comments can NOT substitute; (b) documentation-style (NO steps) but its comments lack numbered action lines and/or a labeled oracle line — prose paragraphs / rationale-only comments export EMPTY Steps + Expected cells | Two valid shapes only: complete the Gherkin with a `Then`, or write the FULL procedure in the `# Tester verifies:` block as NUMBERED lines — action steps first (`1. <action>`), then labeled `Observable:`/`Oracle:`/`Expected:` lines (the number is what fills Steps, the label is what fills Expected results) |
|
|
96
96
|
| `SG-W009` | test-data references `${QA_<NAME>}` (a SECRET env ref) but the name is declared in neither `.env.qa` nor `.env.qa.example` — the test throws "environment variable not set" the moment the key is used. (Only the `${QA_*}` shape is checked; any other `${...}` is literal data and never flagged.) | Add `QA_<NAME>=<value>` to `.env.qa` (gitignored) and list the NAME in `.env.qa.example` (the committed checklist). See `qa/TEST-DATA-GUIDE.md` |
|
|
97
97
|
| `SG-W010` | A row step's `[Ref]` looks POSITIONAL (`First…`/`Last…`/`Top…`/`nth`) but has no selectors.yaml entry — the label is display-only, so the step checks existence ANYWHERE in the table; an ordering/sort-stability rule would pass even when the row moved | Declare the row in selectors.yaml (a `type: locator` value RELATIVE to the table, e.g. `first contact row:` → `value: 'tbody tr:first-child'`) — the step then asserts `toContainText` on that exact row. This is a selectors.yaml-only fix — allowed inside the run-test auto-fix loop |
|
|
98
|
+
| `SG-W011` | A storage assertion written as `expect … in local/session storage` — `expect` steps only read `{{response}}` refs, so this compiles to a silent no-op | Rewrite using the supported grammar: `User see [KEY] in local storage exists/…` |
|
|
99
|
+
| `SG-W012` | A mock-install step written AFTER a navigation step in the same block — `page.route()` registered after `goto()` misses every request fired during page load | Move the mock-install step before the navigation, or into `Background` |
|
|
100
|
+
| `SG-W013` | A page assertion (`see [X] page` / `is on [X] page`) whose `[Ref]` has no `type: page` selector entry (or collides with a non-page entry) — the step falls back to the feature's own path (or `/<ref>/`) instead of `X`'s real URL, so the anchored assertion can never pass | Declare a `type: page` entry for `[Ref]` with its real URL; if the key collides with another type, disambiguate with a `--type` suffix (`sungen-selector-keys` § Collision rule) |
|
|
101
|
+
| `SG-W014` | `[X] page with {{v}}` where `{{v}}`'s base test-data value carries no query and no fragment — the step checks the PATH only, asserting less than it reads as | Informational — pass a value like `?q=…` if you meant to assert a query, or drop `with {{v}}` for a bare page |
|
|
98
102
|
|
|
99
103
|
### Runtime error → `Test data "<key>" references ${QA_*} but the environment variable is not set`
|
|
100
104
|
|
|
@@ -106,11 +106,39 @@ two content-filtered queries can hit different rows if the table re-renders in b
|
|
|
106
106
|
# 8. Page: User see [T] page | page with {{url}} ← `with` also asserts the query string
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
**Pattern 8 —
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
**Pattern 8 — the page assertion judges pathname AND query together.** Both `see [T] page` and
|
|
110
|
+
`is on [T] page` (Then-side) compile to ONE web-first predicate — `toHaveURL(urlMatches({…}))`,
|
|
111
|
+
which retries like any other assertion — comparing the **exact** pathname (anchored, trailing slash
|
|
112
|
+
normalised) plus the query:
|
|
113
|
+
|
|
114
|
+
| step | asserts |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `Then User see [Search] page` | pathname `/vi/search` **and no query at all** — `/vi/search?x=1` FAILS |
|
|
117
|
+
| `… page with {{v}}`, `v` = `?q=abc` | pathname + **every declared param must match**; extra params are tolerated (a UTM/tracking param cannot turn the test red); a repeated param (`?tag=a&tag=b`) matches per value, so param ORDER never matters |
|
|
118
|
+
| `… page with {{v}}`, `v` = `?q=abc#tab` | the fragment is asserted too |
|
|
119
|
+
| `… page with {{v}}`, `v` = `/vi/search?q=abc` | only the query part is used — the page selector already owns the path |
|
|
120
|
+
| `… page with {{v}}`, `v` = `/vi/search` (no query) | **path only**, and the compiler warns (`SG-W014`): the step asserts less than it reads as |
|
|
121
|
+
| `… page with {{v}}`, `v` empty or key missing at run time | **throws, naming the key** — an unusable value is never a silent pass |
|
|
122
|
+
|
|
123
|
+
So pass `with {{v}}` whenever the URL carries state worth proving, and leave it off when the page
|
|
124
|
+
must be reached clean. A dynamic segment in the selector value (`/users/:id/profile`) wildcards to
|
|
125
|
+
`[^/]+` on its own, still anchored — `/users/42/profile/edit` does not match. Params compare
|
|
126
|
+
decoded on both sides, so a deliberately malformed query still asserts what was written.
|
|
127
|
+
|
|
128
|
+
Two asymmetries worth knowing rather than discovering:
|
|
129
|
+
|
|
130
|
+
1. **`Given`/`When` navigate, `Then` asserts** — so they read `{{v}}` differently. `Then` uses only
|
|
131
|
+
its query/fragment; `Given User is on [T] page with {{v}}` also honours a path the value carries
|
|
132
|
+
(`/vi/other?q=1` navigates to `/vi/other?q=1`, and a value repeating the page's own path no
|
|
133
|
+
longer doubles it). Anything that is not a path, query, or fragment is appended **verbatim** —
|
|
134
|
+
nothing is encoded or normalised, so a test can still drive a deliberately malformed query.
|
|
135
|
+
2. **A repeated param matches as a subset per key**, which is the same rule as "extra params are
|
|
136
|
+
tolerated": every value you declare must be present, and the URL may carry more.
|
|
137
|
+
|
|
138
|
+
The predicate itself lives in `specs/url-assert.ts` (auto-generated, `DO NOT EDIT`). If `[T]` has no
|
|
139
|
+
`type: page` selector entry — or its key collides with a non-page entry, so `value` is something like
|
|
140
|
+
`button` rather than a URL — the step falls back to another path and cannot match the real URL. The
|
|
141
|
+
compiler warns (`SG-W013`); declare the page (or rename the colliding key) instead of chasing the red.
|
|
114
142
|
|
|
115
143
|
### Collection / all-card (P5)
|
|
116
144
|
|
|
@@ -97,7 +97,7 @@ When running Phase 0 for a **flow** (`qa/flows/<name>/`), check existing screen
|
|
|
97
97
|
- Loading indicator for `wait for [T] table to refresh` → `feedback.loading.indicator` (skip if the app sets `aria-busy`).
|
|
98
98
|
- **Every qa/app.yaml edit MUST carry provenance** in `detection:`: who/when (`detected_by`) and the observed evidence per key (`evidence:`). A profile without evidence is a guess a human cannot review.
|
|
99
99
|
8. **Merge, don't overwrite**: preserve the page selector and any user-authored entries in `selectors.yaml`. Only add missing keys.
|
|
100
|
-
- **Type-collision check** (see `sungen-selector-keys` § Collision rule): before writing a base key, check whether it already exists with a *different* `type`. If so, give **both** entries a `--type` suffix instead of clobbering or sharing the base key — a base-key entry of the wrong type gets picked up by any step referencing that label. Watch `page` especially: a `[X] page` step reads `value` as a URL, so if `X` already holds a button (`value: 'button'`) the
|
|
100
|
+
- **Type-collision check** (see `sungen-selector-keys` § Collision rule): before writing a base key, check whether it already exists with a *different* `type`. If so, give **both** entries a `--type` suffix instead of clobbering or sharing the base key — a base-key entry of the wrong type gets picked up by any step referencing that label. Watch `page` especially: a `[X] page` step reads `value` as a URL, so if `X` already holds a button (`value: 'button'`) the compiler won't use the button's value as a URL, but it can't invent the real one either — it falls back to the feature's own path and warns `SG-W013`, asserting a page that isn't `X`'s. Write `X--page` (URL from the live page / feature `Path:`) alongside `X--button`.
|
|
101
101
|
9. **Show summary + confirm**: list the keys that will be added, ask the user to approve, then write the file.
|
|
102
102
|
10. **Compile**: **Screen**: `sungen generate --screen <screen>`. **Flow**: `sungen generate --flow <flow>`. Then proceed to Phase 1.
|
|
103
103
|
|
|
@@ -97,12 +97,15 @@ its own `--type` suffix. A key match alone does not carry type: the resolver wal
|
|
|
97
97
|
picked up by any step referencing that label, regardless of the type the step expects.
|
|
98
98
|
|
|
99
99
|
The `page` type is the sharpest trap. A page step (`Then User see [X] page`) reads the entry's
|
|
100
|
-
`value` as a **URL**. If key `X` already holds a `role`/button entry, the
|
|
101
|
-
|
|
100
|
+
`value` as a **URL**. If key `X` already holds a `role`/button entry, the compiler guards the type
|
|
101
|
+
— it does NOT emit `toHaveURL(/button/)` — but it can't invent the real URL either, so it falls
|
|
102
|
+
back to the feature's own path (or `/<ref>/`) and warns `SG-W013`: a test that reads as asserting
|
|
103
|
+
`X`'s page but never can, since the fallback path is anchored and almost certainly wrong.
|
|
102
104
|
|
|
103
105
|
```yaml
|
|
104
106
|
# Gherkin: `When User click [読取結果一覧] button` AND `Then User see [読取結果一覧] page`
|
|
105
|
-
# WRONG — one base key
|
|
107
|
+
# WRONG — one base key: the page step can't use the button's value, falls back to the feature path
|
|
108
|
+
# instead, and the compiler warns SG-W013 rather than asserting the real page:
|
|
106
109
|
読取結果一覧:
|
|
107
110
|
type: 'role'
|
|
108
111
|
value: 'button'
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Sungen URL assertion helper — auto-generated into specs/url-assert.ts. DO NOT EDIT.
|
|
4
|
+
*
|
|
5
|
+
* Every Then-side URL assertion (`see [X] page`, `is on [X] page`) compiles to one call here.
|
|
6
|
+
*
|
|
7
|
+
* Why a helper and not an inline predicate. The predicate used to be emitted inline into every
|
|
8
|
+
* spec, so each correction to what "the URL matches" MEANS was a breaking change for every
|
|
9
|
+
* generated suite in the field: regenerate everything, re-review every newly-red test. Behind a
|
|
10
|
+
* helper the same correction ships as a runtime patch. The generator's job shrinks to what it
|
|
11
|
+
* alone knows — the pathname pattern — and the semantics live in one readable place.
|
|
12
|
+
*
|
|
13
|
+
* Why a predicate and not two assertions. The shape before this one was
|
|
14
|
+
* await expect(page).toHaveURL(/\/vi\/search/); // unanchored: passes on /vi/search-x
|
|
15
|
+
* expect(page.url()).toContain('<query>'); // synchronous, one-shot: never retries
|
|
16
|
+
* — two half-checks, neither anchored, and nothing ever compared pathname and query together.
|
|
17
|
+
* `toHaveURL(predicate)` is web-first (it retries like any other assertion), receives a parsed
|
|
18
|
+
* URL, and needs no regex escaping of runtime values, which is what forced the split.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export interface UrlExpectation {
|
|
22
|
+
/**
|
|
23
|
+
* Anchored pathname pattern, compiled by the generator from the page selector's `value`
|
|
24
|
+
* (`:id` segments already wildcarded). Anchored against `u.pathname` ONLY: pathname never
|
|
25
|
+
* carries the query, so `^…$` is exact there — the same source that was unsafe to anchor
|
|
26
|
+
* against a full URL.
|
|
27
|
+
*/
|
|
28
|
+
pathname: RegExp;
|
|
29
|
+
/**
|
|
30
|
+
* The `with {{v}}` value, raw from test-data: '?q=1' · '/vi/search?q=1' · '#tab' · ''.
|
|
31
|
+
* `undefined` means the step declared nothing, which is itself an assertion — see below.
|
|
32
|
+
*/
|
|
33
|
+
declared?: string;
|
|
34
|
+
/** The test-data key behind `declared`, so a failure can name what an author must go fix. */
|
|
35
|
+
dataRef?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Join a page's URL with the `with {{v}}` value for a NAVIGATION step
|
|
40
|
+
* (`Given User is on [X] page with {{v}}`).
|
|
41
|
+
*
|
|
42
|
+
* Why this is not a plain `base + path + value`. It used to be, and an author writing the value as a
|
|
43
|
+
* whole relative URL — the habit the assertion side already had to accommodate — navigated to
|
|
44
|
+
* `/vi/search/vi/search?q=1`: the page's own path, twice. The Then side then asserted the real path
|
|
45
|
+
* correctly, so the scenario could never go green.
|
|
46
|
+
*
|
|
47
|
+
* `base` (the configured baseURL, possibly '') and `path` (the page selector's value) arrive
|
|
48
|
+
* SEPARATELY so a value that carries its own rooted path replaces the page's path without also
|
|
49
|
+
* discarding a path prefix baked into the baseURL — a deployment under `https://host/tenant-a`
|
|
50
|
+
* would otherwise navigate to the wrong tenant, and only when a `with {{v}}` was present, which is
|
|
51
|
+
* exactly the kind of inconsistency nobody would think to look for.
|
|
52
|
+
*
|
|
53
|
+
* What it deliberately does NOT do is sanitize. A test may legitimately drive a MALFORMED query to
|
|
54
|
+
* prove the app rejects it (issue #464), so anything that is not a duplicated path is appended
|
|
55
|
+
* verbatim: no encoding, no normalising, no reordering.
|
|
56
|
+
*/
|
|
57
|
+
export function joinPath(base: string, path: string, declared?: string | null): string {
|
|
58
|
+
if (declared === undefined || declared === null || declared === '') return base + path;
|
|
59
|
+
const value = String(declared);
|
|
60
|
+
// A query/fragment appends — the overwhelmingly common shape, and the only one #464 needs.
|
|
61
|
+
if (value.startsWith('?') || value.startsWith('#')) return base + path + value;
|
|
62
|
+
// An absolute URL replaces everything: the author pasted a full address.
|
|
63
|
+
if (/^[a-z]+:\/\//i.test(value)) return value;
|
|
64
|
+
// A rooted path carries its own path, so it replaces the PAGE's path while everything the
|
|
65
|
+
// baseURL contributed — scheme, host, and any path prefix — is kept.
|
|
66
|
+
if (value.startsWith('/')) return base + value;
|
|
67
|
+
// Anything else is raw input the test wants appended as-is.
|
|
68
|
+
return base + path + value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `u.pathname` is percent-encoded; a regex built from a selector's literal `value` is not, so a
|
|
73
|
+
* non-ASCII route (`/読取結果一覧`) could never match. Decoding can throw on a lone `%`, in which
|
|
74
|
+
* case the raw form is all there is.
|
|
75
|
+
*/
|
|
76
|
+
function decodedPath(pathname: string): string {
|
|
77
|
+
try {
|
|
78
|
+
return decodeURIComponent(pathname);
|
|
79
|
+
} catch {
|
|
80
|
+
return pathname;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Build the predicate for `expect(page).toHaveURL(...)`.
|
|
86
|
+
*
|
|
87
|
+
* Query semantics are deliberately asymmetric:
|
|
88
|
+
* no `with {{v}}` → the URL must carry NO query. A bare page means a bare page, so
|
|
89
|
+
* `/vi/search` does not pass on `/vi/search?x=1`.
|
|
90
|
+
* `with {{v}}` → every declared param must match; extra params are tolerated, so a
|
|
91
|
+
* tracking/UTM param the test never cared about cannot turn it red.
|
|
92
|
+
* A declared fragment is asserted too; a declared value carrying no query
|
|
93
|
+
* at all constrains the path only (the compiler warns: SG-W014).
|
|
94
|
+
*/
|
|
95
|
+
export function urlMatches({ pathname, declared, dataRef }: UrlExpectation): (u: URL) => boolean {
|
|
96
|
+
return (u: URL): boolean => {
|
|
97
|
+
if (!pathname.test(u.pathname) && !pathname.test(decodedPath(u.pathname))) return false;
|
|
98
|
+
|
|
99
|
+
// `dataRef`, not `declared`, decides which rule applies. Both "the step declared nothing" and
|
|
100
|
+
// "the step declared {{v}} but the key resolved to nothing at runtime" arrive here as
|
|
101
|
+
// undefined, and they mean opposite things: the first is a real assertion (a bare page must be
|
|
102
|
+
// bare), the second is broken test-data. Only the generator knows which, and it says so by
|
|
103
|
+
// emitting `dataRef` exactly when the step carried a `with {{v}}`.
|
|
104
|
+
if (!dataRef) return u.search === '';
|
|
105
|
+
|
|
106
|
+
// Silence is the whole bug class this assertion exists to kill, so an unusable declared value
|
|
107
|
+
// is an ERROR, not a quiet verdict. Returning false would read as "the app is wrong"; these
|
|
108
|
+
// throws say "your test-data is wrong, and here is the key". An empty value used to parse to
|
|
109
|
+
// an empty param list, and `[].every()` is vacuously TRUE — it passed on any query at all.
|
|
110
|
+
if (declared === undefined || declared === null) {
|
|
111
|
+
throw new Error(`url assertion: test-data key "${dataRef}" is missing — nothing to assert`);
|
|
112
|
+
}
|
|
113
|
+
if (String(declared).trim() === '') {
|
|
114
|
+
throw new Error(`url assertion: test-data key "${dataRef}" is empty — nothing to assert`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Parsing against the live pathname as base lets ONE expression handle every shape an author
|
|
118
|
+
// writes: '?q=1' (query only), '/vi/search?q=1' (a whole relative URL — its path is ignored,
|
|
119
|
+
// the page selector already owns the path), and '#tab' (fragment only). The predecessor
|
|
120
|
+
// regex-stripped the prefix instead, which silently turned a value with NO query
|
|
121
|
+
// ('/vi/search') into a bogus param NAME — an assertion that could never be satisfied.
|
|
122
|
+
const d = new URL(String(declared), 'http://sungen.invalid' + u.pathname);
|
|
123
|
+
|
|
124
|
+
// getAll, not get: a multi-select filter (?tag=a&tag=b) is the exact case this assertion is
|
|
125
|
+
// for, and `get()` returns only the first value — so the correct URL failed. Comparing as a
|
|
126
|
+
// subset per key keeps this consistent with "extra params are tolerated", and makes param
|
|
127
|
+
// order meaningless, which is what a URL actually means.
|
|
128
|
+
const queryOk = [...d.searchParams].every(([k, v]) => u.searchParams.getAll(k).includes(v));
|
|
129
|
+
|
|
130
|
+
// Only assert a fragment the author actually declared.
|
|
131
|
+
const hashOk = !d.hash || d.hash === u.hash;
|
|
132
|
+
return queryOk && hashOk;
|
|
133
|
+
};
|
|
134
|
+
}
|