@ia-qa/pal 1.7.1 → 1.8.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.
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.hasScan = exports.discoveryReport = void 0;
37
+ exports.discoverCliEntry = discoverCliEntry;
38
+ exports.scanTheApp = scanTheApp;
39
+ exports.coverageOf = coverageOf;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const child_process_1 = require("child_process");
43
+ /**
44
+ * `@ia-qa/qa-discovery` from pal's console: what exists in the app, and which of it no test visits.
45
+ *
46
+ * Through the sibling's own CLI, with a fixed argv, like the repair console — never a second
47
+ * implementation of a scan or a gap. What comes back is kept to facts (counts, page names, the
48
+ * typed refusal); every sentence about them lives in discovery's own report, which is linked,
49
+ * so the console cannot word the gap differently from the package that computes it.
50
+ *
51
+ * A scan opens the app in a local browser (same site, GET only). Coverage reads files on disk.
52
+ * Neither sends anything anywhere; the BYOK layer (`ia-qa-discover-ai`) is not reached from here.
53
+ */
54
+ function discoverCliEntry() {
55
+ return path.join(path.dirname(require.resolve('@ia-qa/qa-discovery/package.json')), 'dist', 'cli', 'index.js');
56
+ }
57
+ /** Discovery's HTML dossier — one file, rewritten by a scan and again by a coverage run. */
58
+ const discoveryReport = (dir) => path.join(dir, '.ia-qa-discovery', 'report.html');
59
+ exports.discoveryReport = discoveryReport;
60
+ async function run(dir, args, entry, onLine) {
61
+ return new Promise((resolve) => {
62
+ const child = (0, child_process_1.spawn)(process.execPath, [entry, ...args, '--config', dir], { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
63
+ let out = '';
64
+ let err = '';
65
+ child.stdout.on('data', (d) => (out += d.toString()));
66
+ child.stderr.on('data', (d) => {
67
+ err += d.toString();
68
+ for (const line of d.toString().split(/\r?\n/))
69
+ if (line.trim())
70
+ onLine(line.trim());
71
+ });
72
+ child.on('error', (e) => resolve({ code: null, out, err: err + e.message }));
73
+ child.on('close', (code) => resolve({ code, out, err }));
74
+ });
75
+ }
76
+ function parse(out) {
77
+ try {
78
+ const v = JSON.parse(out);
79
+ return v && typeof v === 'object' ? v : null;
80
+ }
81
+ catch {
82
+ return null;
83
+ }
84
+ }
85
+ const lastLines = (err) => err.trim().split(/\r?\n/).slice(-4).join('\n') || 'no output';
86
+ async function scanTheApp(dir, baseUrl, opts = {}) {
87
+ // The session the tour would use, resolved by the caller through the same door — a scan run
88
+ // anonymously on an app behind a login measures the login page and reports it as the app.
89
+ const args = ['scan', baseUrl, '--json', '--report', (0, exports.discoveryReport)(dir), ...(opts.session ? ['--session', opts.session] : [])];
90
+ const { code, out, err } = await run(dir, args, opts.entry ?? discoverCliEntry(), opts.onLine ?? (() => { }));
91
+ const r = parse(out);
92
+ if (code !== 0 || !r)
93
+ return { error: `The scan did not finish (exit ${code ?? 'none'}): ${lastLines(err)}` };
94
+ const diff = (r.diff ?? {});
95
+ return {
96
+ pagesCaptured: Number(r.pagesCaptured ?? 0),
97
+ pagesFound: Number(r.pagesFound ?? 0),
98
+ failed: (r.failed ?? []).map((f) => ({ name: f.name, url: f.url, error: f.error })),
99
+ loginWall: (r.loginWall ?? []),
100
+ hrefBlind: r.hrefBlind === true,
101
+ session: typeof r.session === 'string' ? r.session : null,
102
+ sessionSource: typeof r.sessionSource === 'string' ? r.sessionSource : null,
103
+ added: diff.added ?? [],
104
+ removed: diff.removed ?? [],
105
+ changed: diff.changed ?? [],
106
+ };
107
+ }
108
+ async function coverageOf(dir, opts = {}) {
109
+ const { code, out, err } = await run(dir, ['coverage', '--json', '--report', (0, exports.discoveryReport)(dir)], opts.entry ?? discoverCliEntry(), () => { });
110
+ const r = parse(out);
111
+ if (code !== 0 || !r)
112
+ return { error: `Coverage did not answer (exit ${code ?? 'none'}): ${lastLines(err)}` };
113
+ if (r.measured === false)
114
+ return { measured: false, reason: String(r.reason) };
115
+ const uncovered = (r.uncovered ?? []);
116
+ const suite = (r.suite ?? {});
117
+ return {
118
+ measured: true,
119
+ visited: (r.visited ?? []),
120
+ uncovered: uncovered.slice(0, 12).map((u) => ({ page: u.page, url: u.url, factors: u.factors ?? [] })),
121
+ uncoveredTotal: uncovered.length,
122
+ cannotTell: (r.cannotTell ?? []),
123
+ outOfScope: (r.outOfScope ?? []),
124
+ contractedNotFound: (r.contractedNotFound ?? []),
125
+ notMeasured: (() => {
126
+ const n = (r.notMeasured ?? {});
127
+ return { loginWall: n.loginWall ?? [], hrefBlind: n.hrefBlind === true, droppedByCap: n.droppedByCap ?? 0, session: !!n.session };
128
+ })(),
129
+ recordedAt: suite.recordedAt ?? '',
130
+ scannedAt: String(r.scannedAt ?? ''),
131
+ testCommand: suite.testCommand ?? null,
132
+ };
133
+ }
134
+ const hasScan = (dir) => fs.existsSync(path.join(dir, '.ia-qa-discovery', 'capture', 'surface.json'));
135
+ exports.hasScan = hasScan;
136
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,4CAEC;AA6DD,gCAoBC;AAED,gCAuBC;AA5HD,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAsC;AAEtC;;;;;;;;;;GAUG;AAEH,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AACjH,CAAC;AAED,4FAA4F;AACrF,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,EAAE,aAAa,CAAC,CAAC;AAArF,QAAA,eAAe,mBAAsE;AAgClG,KAAK,UAAU,GAAG,CAAC,GAAW,EAAE,IAAc,EAAE,KAAa,EAAE,MAA8B;IAC3F,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7I,IAAI,GAAG,GAAG,EAAE,CAAC;QAC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