@elisra-devops/docgen-skins 0.27.0 → 0.29.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.
- package/.github/workflows/ci.yml +2 -0
- package/bin/index.js +15 -3
- package/bin/index.js.map +1 -1
- package/bin/models/json/table/JSONTableCell.js +4 -3
- package/bin/models/json/table/JSONTableCell.js.map +1 -1
- package/bin/services/logSink.d.ts +25 -0
- package/bin/services/logSink.js +16 -0
- package/bin/services/logSink.js.map +1 -0
- package/bin/services/logger.d.ts +6 -0
- package/bin/services/logger.js +212 -16
- package/bin/services/logger.js.map +1 -1
- package/bin/services/runContext.d.ts +7 -0
- package/bin/services/runContext.js +12 -0
- package/bin/services/runContext.js.map +1 -0
- package/bin/test/integration/skins.integration.test.js +74 -0
- package/bin/test/integration/skins.integration.test.js.map +1 -1
- package/bin/test/logger.test.d.ts +1 -0
- package/bin/test/logger.test.js +272 -0
- package/bin/test/logger.test.js.map +1 -0
- package/bin/test/runContext.test.d.ts +1 -0
- package/bin/test/runContext.test.js +96 -0
- package/bin/test/runContext.test.js.map +1 -0
- package/eslint.config.mjs +40 -0
- package/package.json +8 -3
- package/src/index.ts +15 -5
- package/src/models/json/table/JSONTableCell.ts +4 -3
- package/src/services/logSink.ts +44 -0
- package/src/services/logger.ts +220 -17
- package/src/services/runContext.ts +22 -0
- package/src/test/integration/skins.integration.test.ts +82 -0
- package/src/test/logger.test.ts +268 -0
- package/src/test/runContext.test.ts +48 -0
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elisra-devops/docgen-skins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Can be outputed in various types:",
|
|
5
5
|
"main": "./bin/index.js",
|
|
6
6
|
"types": "./bin/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "node ./bin/server.js",
|
|
9
9
|
"build": "tsc",
|
|
10
|
-
"test": "jest --coverage --runInBand --forceExit"
|
|
10
|
+
"test": "jest --coverage --runInBand --forceExit",
|
|
11
|
+
"lint": "eslint ."
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -22,12 +23,16 @@
|
|
|
22
23
|
"winston": "^3.2.1"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
26
|
+
"@eslint/js": "^9.39.5",
|
|
25
27
|
"@types/babel__traverse": "^7.20.2",
|
|
26
28
|
"@types/jest": "^29.5.12",
|
|
29
|
+
"eslint": "^9.39.5",
|
|
30
|
+
"globals": "^15.15.0",
|
|
27
31
|
"jest": "^29.7.0",
|
|
28
32
|
"jest-junit": "^16.0.0",
|
|
29
33
|
"ts-jest": "^29.2.3",
|
|
30
|
-
"typescript": "^5.2.2"
|
|
34
|
+
"typescript": "^5.2.2",
|
|
35
|
+
"typescript-eslint": "^8.71.0"
|
|
31
36
|
},
|
|
32
37
|
"jest": {
|
|
33
38
|
"testEnvironment": "node",
|
package/src/index.ts
CHANGED
|
@@ -665,11 +665,14 @@ export default class Skins {
|
|
|
665
665
|
testSkin.push(populatedTableSkin);
|
|
666
666
|
}
|
|
667
667
|
} catch (error) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
668
|
+
// One event, one record — this used to be three separate calls (two
|
|
669
|
+
// warnings plus an error) for a single failure.
|
|
670
|
+
logger.error('Error occurred when building test steps', {
|
|
671
|
+
message: error.message,
|
|
672
|
+
suiteId: testSuite.suiteSkinData.fields[0].value,
|
|
673
|
+
testCaseHeader: testcase.testCaseHeaderSkinData.fields[0].value,
|
|
674
|
+
testCaseStepsSkinData: testcase.testCaseStepsSkinData,
|
|
675
|
+
});
|
|
673
676
|
aggregatedErrors.push(error.message);
|
|
674
677
|
}
|
|
675
678
|
|
|
@@ -973,6 +976,13 @@ export default class Skins {
|
|
|
973
976
|
isBold: true,
|
|
974
977
|
}),
|
|
975
978
|
);
|
|
979
|
+
if (Array.isArray(diff?.stepsTableRows) && diff.stepsTableRows.length > 0) {
|
|
980
|
+
const stepsTable = this.createTableWordObject(diff.stepsTableRows, tableHeaderStyles, normalStyles);
|
|
981
|
+
if (stepsTable) {
|
|
982
|
+
reportWordObjects.push(stepsTable);
|
|
983
|
+
}
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
976
986
|
const baselineValue =
|
|
977
987
|
this.asText(diff?.baselineDisplay) ||
|
|
978
988
|
[baselineRevision, this.asText(diff?.baseline)].filter(Boolean).join(' ');
|
|
@@ -93,9 +93,10 @@ export default class JSONTableCell {
|
|
|
93
93
|
runs = [...runs, ...jsonRun.getRun()];
|
|
94
94
|
}
|
|
95
95
|
} catch (e) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
// One event, one record — three separate calls used to interleave with other
|
|
97
|
+
// requests' output under concurrency and would have become three unrelated
|
|
98
|
+
// entries in the dashboard's error grouping instead of one.
|
|
99
|
+
logger.error('Error generating JSON cell', { message: e.message, data, typeOfDataValue: typeof data.value });
|
|
99
100
|
let jsonRun = new JSONRun('Docgen Error: Invalid data value', styles);
|
|
100
101
|
runs = [...runs, ...jsonRun.getRun()];
|
|
101
102
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The one queryable-error-store event shape, emitted by DiagnosticsTransport (logger.ts).
|
|
4
|
+
// This package never installs a sink itself — it only reads whatever the host process
|
|
5
|
+
// (docgen-content-control's index.ts) installed. err is intentionally narrow —
|
|
6
|
+
// {message, code, stack} — per the settled Phase 6 schema decision: no generic
|
|
7
|
+
// extra-fields bucket.
|
|
8
|
+
export interface DiagnosticEvent {
|
|
9
|
+
ts: string;
|
|
10
|
+
level: string;
|
|
11
|
+
service: string;
|
|
12
|
+
version: string;
|
|
13
|
+
runId?: string;
|
|
14
|
+
docType?: string;
|
|
15
|
+
step?: string;
|
|
16
|
+
contentControlType?: string;
|
|
17
|
+
contentControlTitle?: string;
|
|
18
|
+
project?: string;
|
|
19
|
+
userId?: string;
|
|
20
|
+
message: string;
|
|
21
|
+
err?: { message: string; code?: string; stack?: string };
|
|
22
|
+
// Phase 6b — set on a debug/info event captured under retain-on-failure. Deleted by
|
|
23
|
+
// api-gate at the run's one success point; left alone (and thus permanent, subject to the
|
|
24
|
+
// normal TTL) if the run fails.
|
|
25
|
+
retainPending?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface LogSink {
|
|
29
|
+
push(event: DiagnosticEvent): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Symbol.for so this package's copy converges on the same installed sink as
|
|
33
|
+
// docgen-content-control's (the host process this package runs inside) and
|
|
34
|
+
// docgen-data-provider-package's, the same reasoning as runContext.ts's AsyncLocalStorage. A
|
|
35
|
+
// never-populated sink is a harmless no-op — this package only reads it, never installs one.
|
|
36
|
+
const KEY = Symbol.for("elisradevops.docgen.logSink");
|
|
37
|
+
|
|
38
|
+
export function getLogSink(): LogSink | undefined {
|
|
39
|
+
return (globalThis as Record<symbol, unknown>)[KEY] as LogSink | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function installLogSink(sink: LogSink): void {
|
|
43
|
+
(globalThis as Record<symbol, unknown>)[KEY] = sink;
|
|
44
|
+
}
|
package/src/services/logger.ts
CHANGED
|
@@ -1,26 +1,229 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import * as winston from "winston";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import Transport from "winston-transport";
|
|
6
|
+
import { runContextStore } from "./runContext";
|
|
7
|
+
import { getLogSink, DiagnosticEvent } from "./logSink";
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
// Merges the ambient runId (set by content-control's request middleware, once Phase 3 lands
|
|
10
|
+
// there) into every log record. A never-populated store is a harmless no-op — this package
|
|
11
|
+
// only reads it, never sets it.
|
|
12
|
+
export const withRunContext = winston.format((info) => {
|
|
13
|
+
const store = runContextStore.getStore();
|
|
14
|
+
if (store?.runId) (info as Record<string, unknown>).runId = store.runId;
|
|
15
|
+
// Phase 7b — same ambient, per-run treatment as runId.
|
|
16
|
+
if (store?.docType) (info as Record<string, unknown>).docType = store.docType;
|
|
17
|
+
return info;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Defense-in-depth: scrubs known-sensitive keys out of any object attached to a log
|
|
21
|
+
// call (meta, splat, an Error's own enumerable props). Does not redact secrets
|
|
22
|
+
// interpolated into a message string — that's the corresponding call-site fixes' job;
|
|
23
|
+
// this is a backstop for structured fields.
|
|
24
|
+
// "accesskey" (not just "minioaccesskey") so this also catches an *AccessKeyId-style field —
|
|
25
|
+
// a real gap found in api-gate's copy during the Phase 5 manifest work: only the *SecretKey
|
|
26
|
+
// sibling was covered before, via "secret". Applied here too to keep the four copies in sync.
|
|
27
|
+
const SENSITIVE_KEY = /token|pat|password|secret|authorization|accesskey|minioaccesskey|miniosecretkey/i;
|
|
28
|
+
|
|
29
|
+
// A per-key try/catch on the *read*, not just around the whole loop: a getter that throws
|
|
30
|
+
// (e.g. `{ get boom() { throw ... } }`) would otherwise abort redaction for every remaining
|
|
31
|
+
// key in the same object, or — worse — survive redaction untouched and re-throw later, inside
|
|
32
|
+
// winston's json() formatter, which is not wrapped in anything. redactValue always returns a
|
|
33
|
+
// freshly built plain object/array, never the original reference, so once a value has passed
|
|
34
|
+
// through here nothing downstream can re-trigger a throwing accessor on it.
|
|
35
|
+
function safeRead(obj: Record<string, unknown>, key: string): { ok: true; value: unknown } | { ok: false } {
|
|
36
|
+
try {
|
|
37
|
+
return { ok: true, value: obj[key] };
|
|
38
|
+
} catch {
|
|
39
|
+
return { ok: false };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function redactValue(value: unknown, depth = 0, seen = new WeakSet<object>()): unknown {
|
|
43
|
+
if (depth > 6 || value === null || typeof value !== "object") return value;
|
|
44
|
+
if (seen.has(value as object)) return "[Circular]";
|
|
45
|
+
seen.add(value as object);
|
|
46
|
+
if (Array.isArray(value)) return value.map((v) => redactValue(v, depth + 1, seen));
|
|
47
|
+
const out: Record<string, unknown> = {};
|
|
48
|
+
for (const key of Object.keys(value as Record<string, unknown>)) {
|
|
49
|
+
const read = safeRead(value as Record<string, unknown>, key);
|
|
50
|
+
if (!read.ok) {
|
|
51
|
+
out[key] = "[Unreadable property]";
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
out[key] = SENSITIVE_KEY.test(key) ? "[REDACTED]" : redactValue(read.value, depth + 1, seen);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
export const redact = winston.format((info) => {
|
|
59
|
+
const target = info as Record<string, unknown>;
|
|
60
|
+
for (const key of Object.keys(target)) {
|
|
61
|
+
// level/timestamp are always plain strings winston sets itself — never touched. message is
|
|
62
|
+
// NOT exempt: when logger.error(x) is called with a single non-string/non-Error argument,
|
|
63
|
+
// winston nests the whole thing under info.message (this is exactly the shape hit by a raw
|
|
64
|
+
// object argument), so message can carry a throwing getter or a sensitive key just as much
|
|
65
|
+
// as any other field — redactValue already no-ops on a plain string, so including it here
|
|
66
|
+
// costs nothing for the common case and closes that gap for the uncommon one.
|
|
67
|
+
if (key === "level" || key === "timestamp") continue;
|
|
68
|
+
const read = safeRead(target, key);
|
|
69
|
+
const value = !read.ok
|
|
70
|
+
? "[Unreadable property]"
|
|
71
|
+
: // A top-level primitive (e.g. token: "abc") has no children for redactValue to walk into —
|
|
72
|
+
// the key itself has to be checked here too, not just inside the recursive object walk.
|
|
73
|
+
SENSITIVE_KEY.test(key)
|
|
74
|
+
? "[REDACTED]"
|
|
75
|
+
: redactValue(read.value);
|
|
76
|
+
try {
|
|
77
|
+
target[key] = value;
|
|
78
|
+
} catch {
|
|
79
|
+
// The original property could be a getter-only accessor with no setter, which throws on
|
|
80
|
+
// plain assignment in strict mode — redefine it outright rather than skip it.
|
|
81
|
+
Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return info;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Resolves the package's own version for defaultMeta.
|
|
88
|
+
function readOwnVersion(): string {
|
|
89
|
+
const candidates = [
|
|
90
|
+
path.resolve(__dirname, "../package.json"),
|
|
91
|
+
path.resolve(__dirname, "../../package.json"),
|
|
92
|
+
path.resolve(process.cwd(), "package.json"),
|
|
93
|
+
];
|
|
94
|
+
for (const candidate of candidates) {
|
|
95
|
+
try {
|
|
96
|
+
if (!fs.existsSync(candidate)) continue;
|
|
97
|
+
return JSON.parse(fs.readFileSync(candidate, "utf8")).version || "unknown";
|
|
98
|
+
} catch {
|
|
99
|
+
// try next candidate
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return "unknown";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// A template literal's implicit ToString throws on a Symbol value (unlike String(), which
|
|
106
|
+
// calls Symbol.prototype.toString() explicitly) — logger.error(Symbol('x')) would otherwise
|
|
107
|
+
// crash inside this formatter itself, the one place in the pipeline with no try/catch around
|
|
108
|
+
// it. Symbol.toString() itself never throws, so this needs no further guarding.
|
|
109
|
+
const safeMessageString = (value: unknown): string =>
|
|
110
|
+
typeof value === "symbol" ? value.toString() : String(value);
|
|
111
|
+
|
|
112
|
+
const textFormat = winston.format.printf(
|
|
113
|
+
info => `${info.timestamp} - ${info.level}: ${safeMessageString(info.message)}`
|
|
7
114
|
);
|
|
8
115
|
|
|
116
|
+
// Bounded so one oversized message/stack can't produce an unbounded LogEvent document.
|
|
117
|
+
const MAX_MESSAGE_LEN = 2000;
|
|
118
|
+
const MAX_STACK_LEN = 4000;
|
|
119
|
+
function clamp(value: unknown, max: number): string | undefined {
|
|
120
|
+
if (typeof value !== "string") return undefined;
|
|
121
|
+
return value.length > max ? value.slice(0, max) : value;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Ships warn/error records to whatever LogSink the host process (docgen-content-control's
|
|
125
|
+
// index.ts) has installed — this package never installs one itself, only reads it. Reads
|
|
126
|
+
// info *after* the rest of the format chain has already run — redact() has already scrubbed
|
|
127
|
+
// it by the time this transport sees it. Never throws, never blocks the call path, and never
|
|
128
|
+
// logs through `logger` itself (that would recurse back into this same transport) — failures
|
|
129
|
+
// go to console.error only.
|
|
130
|
+
const DIAGNOSTICS_CAPTURE_ENABLED = (process.env.DIAGNOSTICS_CAPTURE_ENABLED || "true").toLowerCase() !== "false";
|
|
131
|
+
// Exported for tests, the same treatment as redact()/withRunContext() — so a test pipeline
|
|
132
|
+
// can exercise this transport without going through the real singleton logger's env-gated
|
|
133
|
+
// json()/textFormat branch.
|
|
134
|
+
export class DiagnosticsTransport extends Transport {
|
|
135
|
+
log(info: Record<string, unknown>, callback: () => void): void {
|
|
136
|
+
setImmediate(() => this.emit("logged", info));
|
|
137
|
+
try {
|
|
138
|
+
const level = info.level;
|
|
139
|
+
const isWarnOrError = level === "warn" || level === "error";
|
|
140
|
+
// Phase 6b — the logger's own level gate is now 'debug' (see createLogger below), so a
|
|
141
|
+
// debug/info call reaches this transport regardless of mode; this is the one place that
|
|
142
|
+
// decides whether it's actually persisted, keyed off the per-run capture mode rather
|
|
143
|
+
// than a process-wide setting — concurrent runs in 'normal' mode are unaffected by a
|
|
144
|
+
// sibling run's 'verbose'/'retain-on-failure' opt-in.
|
|
145
|
+
const captureMode = runContextStore.getStore()?.captureMode;
|
|
146
|
+
const isCapturedDebugOrInfo =
|
|
147
|
+
(level === "debug" || level === "info") && (captureMode === "verbose" || captureMode === "retain-on-failure");
|
|
148
|
+
if (DIAGNOSTICS_CAPTURE_ENABLED && (isWarnOrError || isCapturedDebugOrInfo)) {
|
|
149
|
+
// winston.errors({stack:true}) merges an Error's own enumerable properties (stack,
|
|
150
|
+
// and anything else the call site set, e.g. `err.code`) directly onto `info` — there
|
|
151
|
+
// is no separate nested info.err. `info.stack`'s presence is the only reliable signal
|
|
152
|
+
// that this record came from `logger.error('...', err)`/`logger.error(err)` rather
|
|
153
|
+
// than a plain string message. When present, info.message is already the
|
|
154
|
+
// stable-message-plus-error-message string winston produced, so err.message reuses it.
|
|
155
|
+
const hasErr = typeof info.stack === "string";
|
|
156
|
+
const message = clamp(info.message, MAX_MESSAGE_LEN) ?? "";
|
|
157
|
+
const event: DiagnosticEvent = {
|
|
158
|
+
ts: typeof info.timestamp === "string" ? info.timestamp : new Date().toISOString(),
|
|
159
|
+
level: String(info.level),
|
|
160
|
+
service: String(info.service ?? "@elisra-devops/docgen-skins"),
|
|
161
|
+
version: String(info.version ?? "unknown"),
|
|
162
|
+
runId: typeof info.runId === "string" ? info.runId : undefined,
|
|
163
|
+
docType: typeof info.docType === "string" ? info.docType : undefined,
|
|
164
|
+
step: typeof info.step === "string" ? info.step : undefined,
|
|
165
|
+
contentControlType: typeof info.contentControlType === "string" ? info.contentControlType : undefined,
|
|
166
|
+
contentControlTitle: typeof info.contentControlTitle === "string" ? info.contentControlTitle : undefined,
|
|
167
|
+
project: typeof info.project === "string" ? info.project : undefined,
|
|
168
|
+
userId: typeof info.userId === "string" ? info.userId : undefined,
|
|
169
|
+
message,
|
|
170
|
+
err: hasErr
|
|
171
|
+
? {
|
|
172
|
+
message,
|
|
173
|
+
code: typeof info.code === "string" ? info.code : undefined,
|
|
174
|
+
stack: clamp(info.stack, MAX_STACK_LEN),
|
|
175
|
+
}
|
|
176
|
+
: undefined,
|
|
177
|
+
retainPending: !isWarnOrError && captureMode === "retain-on-failure" ? true : undefined,
|
|
178
|
+
};
|
|
179
|
+
getLogSink()?.push(event);
|
|
180
|
+
}
|
|
181
|
+
} catch (e) {
|
|
182
|
+
// eslint-disable-next-line no-console
|
|
183
|
+
console.error("DiagnosticsTransport failed to push event", e);
|
|
184
|
+
}
|
|
185
|
+
callback();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// LOG_FORMAT=json is the eventual default (structured stdout a collector can parse), but
|
|
190
|
+
// stays opt-in for one release so switching is a config change, not an image rebuild, if
|
|
191
|
+
// anyone reading raw console output needs to roll back.
|
|
192
|
+
const useJson = (process.env.LOG_FORMAT || "text").toLowerCase() === "json";
|
|
193
|
+
|
|
194
|
+
// Phase 6b — the Logger's own level gate must be 'debug' (winston's most permissive) so a
|
|
195
|
+
// debug/info call always reaches every transport's log(); a static per-logger level can't
|
|
196
|
+
// depend on the ALS store's per-run capture mode, so DiagnosticsTransport has to be the one
|
|
197
|
+
// deciding what's actually persisted. The Console transport below gets its own explicit
|
|
198
|
+
// level so stdout's default behavior (info/warn/error unless LOG_LEVEL=debug) is unchanged —
|
|
199
|
+
// this only spends the format-chain cost on debug() calls that previously short-circuited
|
|
200
|
+
// for free; info/warn/error volume (Phase 4's focus) is unaffected either way.
|
|
201
|
+
const CONSOLE_LOG_LEVEL = process.env.LOG_LEVEL || "info";
|
|
202
|
+
|
|
9
203
|
const logger: winston.Logger = winston.createLogger({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
204
|
+
level: "debug",
|
|
205
|
+
defaultMeta: { service: "@elisra-devops/docgen-skins", version: readOwnVersion() },
|
|
206
|
+
format: useJson
|
|
207
|
+
? winston.format.combine(
|
|
208
|
+
winston.format.errors({ stack: true }),
|
|
209
|
+
winston.format.timestamp(),
|
|
210
|
+
withRunContext(),
|
|
211
|
+
redact(),
|
|
212
|
+
winston.format.splat(),
|
|
213
|
+
winston.format.json()
|
|
214
|
+
)
|
|
215
|
+
: winston.format.combine(
|
|
216
|
+
winston.format.errors({ stack: true }),
|
|
217
|
+
winston.format.timestamp(),
|
|
218
|
+
withRunContext(),
|
|
219
|
+
redact(),
|
|
220
|
+
winston.format.splat(),
|
|
221
|
+
textFormat
|
|
222
|
+
),
|
|
223
|
+
// Stdout only — no File transports, consistent with the other DocGen services (no mounted
|
|
224
|
+
// log volume anywhere in this deployment, so a File transport is invisible to `kubectl logs`
|
|
225
|
+
// and can throw at import time under a read-only root filesystem).
|
|
226
|
+
transports: [new winston.transports.Console({ level: CONSOLE_LOG_LEVEL }), new DiagnosticsTransport()]
|
|
24
227
|
});
|
|
25
228
|
|
|
26
229
|
export default logger;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
|
|
4
|
+
export interface RunContext {
|
|
5
|
+
runId: string;
|
|
6
|
+
// Phase 6b — this package never sets it, only reads it: content-control (the host process
|
|
7
|
+
// this package runs in-process inside) populates it via its own attachRunContext, and this
|
|
8
|
+
// package's DiagnosticsTransport reads the same in-process ALS store.
|
|
9
|
+
captureMode?: 'verbose' | 'retain-on-failure';
|
|
10
|
+
// Phase 7b — same read-only treatment as captureMode above.
|
|
11
|
+
docType?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Symbol.for uses the global symbol registry, so every duplicated copy of this file across
|
|
15
|
+
// the DocGen packages — hoisted or nested at any depth by npm — converges on the same
|
|
16
|
+
// AsyncLocalStorage instance. Keying by module identity instead would silently split into
|
|
17
|
+
// two stores and runId would go missing with no visible error.
|
|
18
|
+
const KEY = Symbol.for("elisradevops.docgen.runContext");
|
|
19
|
+
|
|
20
|
+
export const runContextStore: AsyncLocalStorage<RunContext> =
|
|
21
|
+
((globalThis as Record<symbol, unknown>)[KEY] as AsyncLocalStorage<RunContext> | undefined) ??
|
|
22
|
+
((globalThis as Record<symbol, unknown>)[KEY] = new AsyncLocalStorage<RunContext>());
|
|
@@ -715,4 +715,86 @@ describe('Time machine report skin - tests', () => {
|
|
|
715
715
|
expect(baselineCell.Html.Html).toBe('<p>2</p><p>Old cleaned</p>');
|
|
716
716
|
expect(compareCell.Html.Html).toBe('<p>20</p><p>New cleaned</p>');
|
|
717
717
|
});
|
|
718
|
+
|
|
719
|
+
test('renders a Steps difference carrying stepsTableRows as its own paired-row table, skipping the generic Baseline|Compare-to table', async () => {
|
|
720
|
+
const skins = new Skins('json', 'c\\test\\test.dotx');
|
|
721
|
+
const stepsTableRows = [
|
|
722
|
+
{
|
|
723
|
+
url: '',
|
|
724
|
+
fields: [
|
|
725
|
+
{ name: '', value: 'Updated step 1', width: '16%' },
|
|
726
|
+
{ name: 'Action', value: '<p>Open the app</p>', width: '32%' },
|
|
727
|
+
{ name: 'Expected Result', value: '', width: '32%' },
|
|
728
|
+
{ name: 'Attachments', value: [], width: '20%' },
|
|
729
|
+
],
|
|
730
|
+
Source: 11,
|
|
731
|
+
level: 0,
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
url: '',
|
|
735
|
+
fields: [
|
|
736
|
+
{ name: '', value: 'Previous step 1', width: '16%' },
|
|
737
|
+
{ name: 'Action', value: '<p>Open app</p>', width: '32%' },
|
|
738
|
+
{ name: 'Expected Result', value: '', width: '32%' },
|
|
739
|
+
{ name: 'Attachments', value: [], width: '20%' },
|
|
740
|
+
],
|
|
741
|
+
Source: 11,
|
|
742
|
+
level: 0,
|
|
743
|
+
},
|
|
744
|
+
];
|
|
745
|
+
const result = await skins.addNewContentToDocumentSkin(
|
|
746
|
+
'historical-compare-report-content-control',
|
|
747
|
+
skins.SKIN_TYPE_TIME_MACHINE,
|
|
748
|
+
{
|
|
749
|
+
teamProjectName: 'MEWP',
|
|
750
|
+
queryName: 'Shared Query',
|
|
751
|
+
compareResult: {
|
|
752
|
+
baseline: { asOf: '2025-12-22T17:08:00.000Z', total: 1 },
|
|
753
|
+
compareTo: { asOf: '2025-12-28T08:57:00.000Z', total: 1 },
|
|
754
|
+
summary: { updatedCount: 1 },
|
|
755
|
+
rows: [
|
|
756
|
+
{
|
|
757
|
+
id: 11,
|
|
758
|
+
workItemType: 'Test Case',
|
|
759
|
+
title: 'Case-11',
|
|
760
|
+
workItemUrl: 'https://dev.azure.com/org/project/_workitems/edit/11',
|
|
761
|
+
baselineRevisionId: 2,
|
|
762
|
+
compareToRevisionId: 20,
|
|
763
|
+
compareStatus: 'Changed',
|
|
764
|
+
differences: [
|
|
765
|
+
{
|
|
766
|
+
field: 'Steps',
|
|
767
|
+
baseline: '<steps/>',
|
|
768
|
+
compareTo: '<steps/>',
|
|
769
|
+
stepsTableRows,
|
|
770
|
+
},
|
|
771
|
+
],
|
|
772
|
+
},
|
|
773
|
+
],
|
|
774
|
+
},
|
|
775
|
+
},
|
|
776
|
+
headerStyles,
|
|
777
|
+
styles,
|
|
778
|
+
1,
|
|
779
|
+
);
|
|
780
|
+
|
|
781
|
+
const cellText = (cell: any) => cell.Paragraphs?.[0]?.Runs?.[0]?.text || '';
|
|
782
|
+
const tables = result.filter((item: any) => item?.type === 'table');
|
|
783
|
+
const stepsTable = tables.find((table: any) => cellText(table.Rows[0].Cells[1]) === 'Action') as any;
|
|
784
|
+
expect(stepsTable).toBeTruthy();
|
|
785
|
+
// Header labels come from the first row's field names.
|
|
786
|
+
const headerRow = stepsTable.Rows[0];
|
|
787
|
+
expect(headerRow.Cells.map(cellText)).toEqual(['', 'Action', 'Expected Result', 'Attachments']);
|
|
788
|
+
// Both step-side rows are present, in order.
|
|
789
|
+
const bodyRows = stepsTable.Rows.slice(1);
|
|
790
|
+
expect(bodyRows).toHaveLength(2);
|
|
791
|
+
expect(cellText(bodyRows[0].Cells[0])).toBe('Updated step 1');
|
|
792
|
+
expect(bodyRows[0].Cells[1].Html?.Html).toBe('<p>Open the app</p>');
|
|
793
|
+
expect(cellText(bodyRows[1].Cells[0])).toBe('Previous step 1');
|
|
794
|
+
expect(bodyRows[1].Cells[1].Html?.Html).toBe('<p>Open app</p>');
|
|
795
|
+
// No generic "Baseline"/"Compare to" table (the fallback used for every other field) was
|
|
796
|
+
// emitted for the Steps field specifically - i.e. exactly one table has that header shape.
|
|
797
|
+
const genericDiffTables = tables.filter((table: any) => cellText(table.Rows[0].Cells[0]) === 'Baseline');
|
|
798
|
+
expect(genericDiffTables).toHaveLength(0);
|
|
799
|
+
});
|
|
718
800
|
});
|