taf-git 0.0.0-stage → 3.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +413 -0
  2. package/LICENSE +21 -0
  3. package/README.md +266 -2
  4. package/RECEIPT-FORMAT.md +100 -0
  5. package/dist/badge.d.ts +23 -0
  6. package/dist/badge.js +150 -0
  7. package/dist/badge.js.map +1 -0
  8. package/dist/cli.d.ts +42 -0
  9. package/dist/cli.js +323 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/git-env.d.ts +20 -0
  12. package/dist/git-env.js +45 -0
  13. package/dist/git-env.js.map +1 -0
  14. package/dist/index.d.ts +7 -0
  15. package/dist/parsers/bun.d.ts +58 -0
  16. package/dist/parsers/bun.js +126 -0
  17. package/dist/parsers/bun.js.map +1 -0
  18. package/dist/parsers/index.d.ts +21 -0
  19. package/dist/parsers/index.js +63 -0
  20. package/dist/parsers/index.js.map +1 -0
  21. package/dist/parsers/jest.d.ts +41 -0
  22. package/dist/parsers/jest.js +87 -0
  23. package/dist/parsers/jest.js.map +1 -0
  24. package/dist/parsers/junit.d.ts +24 -0
  25. package/dist/parsers/junit.js +144 -0
  26. package/dist/parsers/junit.js.map +1 -0
  27. package/dist/parsers/vitest.d.ts +16 -0
  28. package/dist/parsers/vitest.js +61 -0
  29. package/dist/parsers/vitest.js.map +1 -0
  30. package/dist/parsers/wjttc.d.ts +37 -0
  31. package/dist/parsers/wjttc.js +152 -0
  32. package/dist/parsers/wjttc.js.map +1 -0
  33. package/dist/receipt-push.d.ts +38 -0
  34. package/dist/receipt-push.js +63 -0
  35. package/dist/receipt-push.js.map +1 -0
  36. package/dist/skipped-names.d.ts +60 -0
  37. package/dist/skipped-names.js +159 -0
  38. package/dist/skipped-names.js.map +1 -0
  39. package/dist/taf-core.d.ts +32 -0
  40. package/dist/taf-core.js +303 -0
  41. package/dist/taf-core.js.map +1 -0
  42. package/package.json +64 -4
  43. package/project.faf +57 -0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Push a receipt, and try again when another run got there first.
3
+ *
4
+ * Two runs that finish close together both commit a receipt on top of the
5
+ * same branch tip; the second push is rejected (non-fast-forward). Before
6
+ * 2.4.3 that was a warning and the receipt was lost. Now the run fetches the
7
+ * branch again, catches up with it, adds its receipt to the fresh .taf, and
8
+ * pushes, up to `attempts` times.
9
+ *
10
+ * Catching up: the receipt is written in a temporary worktree on a detached
11
+ * HEAD (the receipts branch, or for the current branch a worktree at the
12
+ * remote tip that holds only .taf), never in the job's own checkout. HEAD is
13
+ * moved to the remote tip and .taf taken from it, which throws away only this
14
+ * run's own rejected receipt commit and touches no other file; the job's
15
+ * checkout is never moved, so later steps run on the code that was tested.
16
+ * Tries are spaced by a short random wait, so runs that keep colliding drift
17
+ * apart.
18
+ *
19
+ * Both push HEAD to the branch and fetch with an explicit refspec (a
20
+ * single-branch checkout's fetch config doesn't cover a receipts branch).
21
+ */
22
+ /** Runs git with these args in the repo; resolves to the exit code. */
23
+ export type Git = (args: string[]) => Promise<number>;
24
+ export interface PushResult {
25
+ pushed: boolean;
26
+ attempts: number;
27
+ }
28
+ export interface PushOptions {
29
+ /** How many pushes to try. Default 5. */
30
+ attempts?: number;
31
+ /** The remote to fetch from and push to. Default `origin`. */
32
+ remote?: string;
33
+ /** Asked after a failed push: is another try worth it? Default: always. */
34
+ retry?: () => boolean;
35
+ /** Waits before try `attempt` (2 and up). Default: a random 0.5 to 1.5 s, times (attempt - 1). */
36
+ wait?: (attempt: number) => Promise<void>;
37
+ }
38
+ export declare function pushReceipt(git: Git, targetBranch: string, message: string, addReceipt: () => boolean, options?: PushOptions): Promise<PushResult>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /**
3
+ * Push a receipt, and try again when another run got there first.
4
+ *
5
+ * Two runs that finish close together both commit a receipt on top of the
6
+ * same branch tip; the second push is rejected (non-fast-forward). Before
7
+ * 2.4.3 that was a warning and the receipt was lost. Now the run fetches the
8
+ * branch again, catches up with it, adds its receipt to the fresh .taf, and
9
+ * pushes, up to `attempts` times.
10
+ *
11
+ * Catching up: the receipt is written in a temporary worktree on a detached
12
+ * HEAD (the receipts branch, or for the current branch a worktree at the
13
+ * remote tip that holds only .taf), never in the job's own checkout. HEAD is
14
+ * moved to the remote tip and .taf taken from it, which throws away only this
15
+ * run's own rejected receipt commit and touches no other file; the job's
16
+ * checkout is never moved, so later steps run on the code that was tested.
17
+ * Tries are spaced by a short random wait, so runs that keep colliding drift
18
+ * apart.
19
+ *
20
+ * Both push HEAD to the branch and fetch with an explicit refspec (a
21
+ * single-branch checkout's fetch config doesn't cover a receipts branch).
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.pushReceipt = pushReceipt;
25
+ const randomWait = (attempt) => new Promise((resolve) => setTimeout(resolve, (500 + Math.random() * 1000) * (attempt - 1)));
26
+ async function pushReceipt(git, targetBranch, message, addReceipt, options = {}) {
27
+ const { attempts = 5, remote = 'origin', retry = () => true, wait = randomWait } = options;
28
+ const remoteRef = `refs/remotes/${remote}/${targetBranch}`;
29
+ // Name .taf on both: the receipt commit holds the receipt and nothing else.
30
+ const commit = async () => (await git(['add', '--', '.taf'])) === 0 && (await git(['commit', '-m', message, '--', '.taf'])) === 0;
31
+ // Pushes actually tried: a fetch or commit that fails ends the loop early.
32
+ let pushes = 0;
33
+ for (let attempt = 1; attempt <= attempts; attempt++) {
34
+ if (attempt > 1) {
35
+ // Another run pushed first: start again from its receipts.
36
+ await wait(attempt);
37
+ if ((await git(['fetch', remote, `+refs/heads/${targetBranch}:${remoteRef}`])) !== 0) {
38
+ break;
39
+ }
40
+ if ((await git(['reset', '--soft', remoteRef])) !== 0) {
41
+ break;
42
+ }
43
+ if ((await git(['checkout', remoteRef, '--', '.taf'])) !== 0) {
44
+ break;
45
+ }
46
+ if (!addReceipt()) {
47
+ break;
48
+ }
49
+ }
50
+ if (!(await commit())) {
51
+ break;
52
+ }
53
+ pushes++;
54
+ if ((await git(['push', remote, `HEAD:refs/heads/${targetBranch}`])) === 0) {
55
+ return { pushed: true, attempts: pushes };
56
+ }
57
+ if (!retry()) {
58
+ break;
59
+ }
60
+ }
61
+ return { pushed: false, attempts: pushes };
62
+ }
63
+ //# sourceMappingURL=receipt-push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt-push.js","sourceRoot":"","sources":["../src/receipt-push.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAwBH,kCA8BC;AAjCD,MAAM,UAAU,GAAG,CAAC,OAAe,EAAiB,EAAE,CACpD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvF,KAAK,UAAU,WAAW,CAC/B,GAAQ,EACR,YAAoB,EACpB,OAAe,EACf,UAAyB,EACzB,UAAuB,EAAE;IAEzB,MAAM,EAAE,QAAQ,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,EAAE,KAAK,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAC3F,MAAM,SAAS,GAAG,gBAAgB,MAAM,IAAI,YAAY,EAAE,CAAC;IAC3D,4EAA4E;IAC5E,MAAM,MAAM,GAAG,KAAK,IAAsB,EAAE,CAC1C,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAEzG,2EAA2E;IAC3E,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,I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2
+ * Skipped test names on the receipt
3
+ *
4
+ * A count can stay the same while the tests behind it change: yesterday's 3
5
+ * skipped tests and today's 3 may not be the same 3. So a receipt can carry
6
+ * the skipped names, a hash of the full set, and what changed since the
7
+ * previous receipt (RECEIPT-FORMAT.md v1.1, `skipped_tests`).
8
+ *
9
+ * The list is capped (25 by default) so a receipt stays small; the hash always
10
+ * covers the full set, so a reader can tell "same set" from "different set"
11
+ * even past the cap.
12
+ */
13
+ /** Default number of names written on a receipt. 0 turns the block off. */
14
+ export declare const DEFAULT_SKIPPED_NAMES_CAP = 25;
15
+ /**
16
+ * The `skipped-names` setting: a whole number of names to write, 0 for off.
17
+ * Empty means the default. Anything else is an error, so a typo can't turn
18
+ * the feature off unnoticed.
19
+ */
20
+ export declare function parseSkippedNamesCap(raw: string | undefined): number;
21
+ export interface SkippedTestsBlock {
22
+ names: string[];
23
+ truncated?: true;
24
+ hash: string;
25
+ newly_skipped?: string[];
26
+ no_longer_skipped?: string[];
27
+ }
28
+ /** What a previous receipt entry needs to look like for the comparison. */
29
+ export interface PreviousEntry {
30
+ tests?: {
31
+ skipped?: number;
32
+ };
33
+ skipped_tests?: Partial<SkippedTestsBlock>;
34
+ }
35
+ /** The block to write (or none), and a one-line reason when there is none. */
36
+ export interface SkippedTestsOutcome {
37
+ block?: SkippedTestsBlock;
38
+ reason?: string;
39
+ }
40
+ /** Turn &gt; &#62; &#x3e; back into characters. */
41
+ export declare function decodeXmlEntities(text: string): string;
42
+ /**
43
+ * One name, made stable across runs and machines: no colour codes, NFC,
44
+ * single spaces, no timing suffix, no absolute path prefix, at most 200
45
+ * characters.
46
+ */
47
+ export declare function normalizeName(raw: string): string;
48
+ /** Sorted by code unit (no locale), duplicates kept: the same set always sorts the same. */
49
+ export declare function sortNames(names: readonly string[]): string[];
50
+ /** sha256 of the sorted names joined with "\n", UTF-8. */
51
+ export declare function hashNames(sorted: readonly string[]): string;
52
+ /**
53
+ * Build the `skipped_tests` block for a new receipt.
54
+ *
55
+ * @param rawNames names the parser read, or undefined when the format names none
56
+ * @param skipped this run's skipped count
57
+ * @param prev the last receipt in test_history (undefined on the first)
58
+ * @param cap names to write; 0 turns the block off
59
+ */
60
+ export declare function buildSkippedTests(rawNames: readonly string[] | undefined, skipped: number, prev: PreviousEntry | undefined, cap?: number): SkippedTestsOutcome;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /**
3
+ * Skipped test names on the receipt
4
+ *
5
+ * A count can stay the same while the tests behind it change: yesterday's 3
6
+ * skipped tests and today's 3 may not be the same 3. So a receipt can carry
7
+ * the skipped names, a hash of the full set, and what changed since the
8
+ * previous receipt (RECEIPT-FORMAT.md v1.1, `skipped_tests`).
9
+ *
10
+ * The list is capped (25 by default) so a receipt stays small; the hash always
11
+ * covers the full set, so a reader can tell "same set" from "different set"
12
+ * even past the cap.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DEFAULT_SKIPPED_NAMES_CAP = void 0;
16
+ exports.parseSkippedNamesCap = parseSkippedNamesCap;
17
+ exports.decodeXmlEntities = decodeXmlEntities;
18
+ exports.normalizeName = normalizeName;
19
+ exports.sortNames = sortNames;
20
+ exports.hashNames = hashNames;
21
+ exports.buildSkippedTests = buildSkippedTests;
22
+ const crypto_1 = require("crypto");
23
+ /** Default number of names written on a receipt. 0 turns the block off. */
24
+ exports.DEFAULT_SKIPPED_NAMES_CAP = 25;
25
+ /**
26
+ * The `skipped-names` setting: a whole number of names to write, 0 for off.
27
+ * Empty means the default. Anything else is an error, so a typo can't turn
28
+ * the feature off unnoticed.
29
+ */
30
+ function parseSkippedNamesCap(raw) {
31
+ const value = (raw ?? '').trim();
32
+ if (value === '')
33
+ return exports.DEFAULT_SKIPPED_NAMES_CAP;
34
+ if (!/^\d+$/.test(value))
35
+ throw new Error(`skipped-names must be a whole number (0 turns it off), got "${value}"`);
36
+ return parseInt(value, 10);
37
+ }
38
+ /** Longest name kept, in characters; longer names are cut. */
39
+ const MAX_NAME_LENGTH = 200;
40
+ const XML_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
41
+ /** Turn &gt; &#62; &#x3e; back into characters. */
42
+ function decodeXmlEntities(text) {
43
+ return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, ref) => {
44
+ if (ref[0] === '#') {
45
+ const code = ref[1].toLowerCase() === 'x' ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
46
+ return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
47
+ }
48
+ return XML_ENTITIES[ref.toLowerCase()] ?? whole;
49
+ });
50
+ }
51
+ /**
52
+ * One name, made stable across runs and machines: no colour codes, NFC,
53
+ * single spaces, no timing suffix, no absolute path prefix, at most 200
54
+ * characters.
55
+ */
56
+ function normalizeName(raw) {
57
+ let name = raw
58
+ // eslint-disable-next-line no-control-regex
59
+ .replace(/\x1b\[[0-9;]*m/g, '')
60
+ .normalize('NFC')
61
+ .replace(/\s+/g, ' ')
62
+ .trim()
63
+ // timing suffixes: "[0.38ms]", "(12 ms)", "(1.2s)"
64
+ .replace(/\s*[[(]\d+(?:\.\d+)?\s*m?s[\])]$/, '')
65
+ // absolute path prefixes (a CI work folder, a home folder, a Windows drive
66
+ // path) at the start or after a space; relative paths like sub/a.test.ts stay
67
+ .replace(/(^|[\s(])(?:[A-Za-z]:)?[\\/](?:[^\s\\/:>]+[\\/])+(?=[^\s\\/]+)/g, '$1');
68
+ if (name.length > MAX_NAME_LENGTH)
69
+ name = name.slice(0, MAX_NAME_LENGTH);
70
+ return name;
71
+ }
72
+ /** Sorted by code unit (no locale), duplicates kept: the same set always sorts the same. */
73
+ function sortNames(names) {
74
+ return [...names].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
75
+ }
76
+ /** sha256 of the sorted names joined with "\n", UTF-8. */
77
+ function hashNames(sorted) {
78
+ return `sha256:${(0, crypto_1.createHash)('sha256').update(sorted.join('\n'), 'utf8').digest('hex')}`;
79
+ }
80
+ /**
81
+ * The previous receipt's skipped set: a full list, a hash only, or unknown.
82
+ * - a block that isn't truncated gives its names
83
+ * - a truncated block gives its hash only
84
+ * - no block and no skips: the set was empty (works for receipts from before 2.5.0)
85
+ * - no block but skips: unknown
86
+ */
87
+ function previousSet(prev) {
88
+ if (!prev)
89
+ return undefined;
90
+ const block = prev.skipped_tests;
91
+ if (block && typeof block === 'object') {
92
+ if (!block.truncated && Array.isArray(block.names))
93
+ return { names: sortNames(block.names.map(String)) };
94
+ if (typeof block.hash === 'string')
95
+ return { hash: block.hash };
96
+ return undefined;
97
+ }
98
+ return (prev.tests?.skipped ?? 0) === 0 ? { names: [] } : undefined;
99
+ }
100
+ /** a − b as multisets, sorted. */
101
+ function difference(a, b) {
102
+ const left = new Map();
103
+ for (const n of b)
104
+ left.set(n, (left.get(n) ?? 0) + 1);
105
+ const out = [];
106
+ for (const n of a) {
107
+ const k = left.get(n) ?? 0;
108
+ if (k > 0)
109
+ left.set(n, k - 1);
110
+ else
111
+ out.push(n);
112
+ }
113
+ return out;
114
+ }
115
+ /**
116
+ * Build the `skipped_tests` block for a new receipt.
117
+ *
118
+ * @param rawNames names the parser read, or undefined when the format names none
119
+ * @param skipped this run's skipped count
120
+ * @param prev the last receipt in test_history (undefined on the first)
121
+ * @param cap names to write; 0 turns the block off
122
+ */
123
+ function buildSkippedTests(rawNames, skipped, prev, cap = exports.DEFAULT_SKIPPED_NAMES_CAP) {
124
+ if (cap <= 0)
125
+ return {};
126
+ const before = previousSet(prev);
127
+ if (skipped === 0) {
128
+ // Back to zero: say which ones stopped being skipped, if there were any.
129
+ if (before?.names && before.names.length > 0) {
130
+ return { block: { names: [], hash: hashNames([]), no_longer_skipped: before.names } };
131
+ }
132
+ if (before?.hash && before.hash !== hashNames([])) {
133
+ return { block: { names: [], hash: hashNames([]) } };
134
+ }
135
+ return {};
136
+ }
137
+ if (!rawNames) {
138
+ return { reason: `${skipped} skipped, but this test output does not name skipped tests` };
139
+ }
140
+ if (rawNames.length !== skipped) {
141
+ return {
142
+ reason: `${skipped} skipped, but ${rawNames.length} skipped name${rawNames.length === 1 ? '' : 's'} found in the output; names left off`,
143
+ };
144
+ }
145
+ const all = sortNames(rawNames.map(normalizeName));
146
+ const block = { names: all.slice(0, cap), hash: hashNames(all) };
147
+ if (all.length > cap)
148
+ block.truncated = true;
149
+ if (before?.names) {
150
+ const newly = difference(all, before.names);
151
+ const gone = difference(before.names, all);
152
+ if (newly.length > 0)
153
+ block.newly_skipped = newly;
154
+ if (gone.length > 0)
155
+ block.no_longer_skipped = gone;
156
+ }
157
+ return { block };
158
+ }
159
+ //# sourceMappingURL=skipped-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skipped-names.js","sourceRoot":"","sources":["../src/skipped-names.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAYH,oDAKC;AA4BD,8CAQC;AAOD,sCAcC;AAGD,8BAEC;AAGD,8BAEC;AAyCD,8CAyCC;AApKD,mCAAoC;AAEpC,2EAA2E;AAC9D,QAAA,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,GAAuB;IAC1D,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,iCAAyB,CAAC;IACnD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,+DAA+D,KAAK,GAAG,CAAC,CAAC;IACnH,OAAO,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,8DAA8D;AAC9D,MAAM,eAAe,GAAG,GAAG,CAAC;AAsB5B,MAAM,YAAY,GAA2B,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,E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CAAC;IACtD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * TAF Core - Simplified for GitHub Action
3
+ *
4
+ * Pure functions for reading, parsing, and updating .taf files
5
+ * Derived from faf-cli TAF implementation (MCP-portable)
6
+ */
7
+ import { TestResults } from './parsers/jest';
8
+ import { SkippedTestsBlock } from './skipped-names';
9
+ export interface UpdateOptions {
10
+ /** Skipped names to write; 0 turns the skipped_tests block off. */
11
+ skippedNamesCap?: number;
12
+ }
13
+ /** What the last updateTafFile call wrote, for outputs and logs. */
14
+ export interface UpdateReport {
15
+ skippedTests?: SkippedTestsBlock;
16
+ /** Why no skipped_tests block was written although tests were skipped. */
17
+ skippedNamesNote?: string;
18
+ }
19
+ export declare const lastUpdate: UpdateReport;
20
+ /**
21
+ * Update .taf file with new test results
22
+ * Creates the file if it doesn't exist
23
+ */
24
+ export declare function updateTafFile(tafPath: string, testResults: TestResults, options?: UpdateOptions): boolean;
25
+ /**
26
+ * What fired the run: GitHub Actions, another CI, or a local run
27
+ */
28
+ export declare function runTrigger(env?: NodeJS.ProcessEnv): string;
29
+ /**
30
+ * The error when there is no .taf to append to, with the command that makes one
31
+ */
32
+ export declare const NO_TAF_FILE = "No .taf file found. Create one: echo 'test_history: []' > .taf";
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+ /**
3
+ * TAF Core - Simplified for GitHub Action
4
+ *
5
+ * Pure functions for reading, parsing, and updating .taf files
6
+ * Derived from faf-cli TAF implementation (MCP-portable)
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.NO_TAF_FILE = exports.lastUpdate = void 0;
43
+ exports.updateTafFile = updateTafFile;
44
+ exports.runTrigger = runTrigger;
45
+ const fs = __importStar(require("fs"));
46
+ const os = __importStar(require("os"));
47
+ const path = __importStar(require("path"));
48
+ const yaml = __importStar(require("yaml"));
49
+ const skipped_names_1 = require("./skipped-names");
50
+ exports.lastUpdate = {};
51
+ /**
52
+ * Update .taf file with new test results
53
+ * Creates the file if it doesn't exist
54
+ */
55
+ function updateTafFile(tafPath, testResults, options = {}) {
56
+ try {
57
+ return withTafLock(tafPath, () => appendReceipt(tafPath, testResults, options));
58
+ }
59
+ catch (error) {
60
+ console.error('Failed to update .taf file:', error);
61
+ return false;
62
+ }
63
+ }
64
+ /**
65
+ * Read, add one receipt, write. Runs under the .taf lock.
66
+ *
67
+ * The receipts document is edited as YAML, not rebuilt from an object, so its
68
+ * comments and key order stay. Anything after it (a later `---` document, even
69
+ * one with a YAML error) is kept byte for byte.
70
+ */
71
+ function appendReceipt(tafPath, testResults, options) {
72
+ let doc;
73
+ let tail = '';
74
+ if (fs.existsSync(tafPath)) {
75
+ ({ doc, tail } = readTaf(fs.readFileSync(tafPath, 'utf-8')));
76
+ }
77
+ else {
78
+ doc = new yaml.Document(createTAF(path.basename(path.dirname(tafPath))));
79
+ }
80
+ const taf = doc.toJS();
81
+ // Create test run entry
82
+ const run = {
83
+ timestamp: new Date().toISOString(),
84
+ result: testResults.result,
85
+ tests: {
86
+ total: testResults.total,
87
+ passed: testResults.passed,
88
+ failed: testResults.failed,
89
+ skipped: testResults.skipped,
90
+ },
91
+ trigger: runTrigger(),
92
+ };
93
+ // Skipped names, compared with the receipt before this one. On a push-race
94
+ // retry this runs again against the receipts that won, so the diff is
95
+ // always against the true previous receipt.
96
+ const previous = taf.test_history[taf.test_history.length - 1];
97
+ const skipped = (0, skipped_names_1.buildSkippedTests)(testResults.skippedNames, testResults.skipped ?? 0, previous, options.skippedNamesCap ?? skipped_names_1.DEFAULT_SKIPPED_NAMES_CAP);
98
+ if (skipped.block)
99
+ run.skipped_tests = skipped.block;
100
+ exports.lastUpdate.skippedTests = skipped.block;
101
+ exports.lastUpdate.skippedNamesNote = skipped.reason;
102
+ // Append to history, in block style even when the file had `test_history: []`.
103
+ const history = doc.get('test_history', true);
104
+ if (yaml.isSeq(history)) {
105
+ history.flow = false;
106
+ }
107
+ doc.addIn(['test_history'], run);
108
+ doc.set('last_updated', new Date().toISOString());
109
+ writeAtomically(tafPath, String(doc) + tail);
110
+ return true;
111
+ }
112
+ /** How long a writer waits for another one's lock, and when any lock counts as left behind. */
113
+ const LOCK_WAIT_MS = 30000;
114
+ const LOCK_STALE_MS = 60000;
115
+ const sleep = (ms) => { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); };
116
+ const readFileOrNull = (file) => {
117
+ try {
118
+ return fs.readFileSync(file, 'utf-8');
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ };
124
+ /**
125
+ * True when the lock's owner can't still be writing: a process on this
126
+ * machine that has exited, or a lock older than LOCK_STALE_MS (a writer holds
127
+ * it for milliseconds, so an old lock is left over whoever's PID it names:
128
+ * another machine's, or one reused since).
129
+ */
130
+ function lockIsStale(token, lock) {
131
+ try {
132
+ if (Date.now() - fs.statSync(lock).mtimeMs > LOCK_STALE_MS) {
133
+ return true;
134
+ }
135
+ }
136
+ catch {
137
+ return false; // gone: not stale, just free
138
+ }
139
+ const [host, pidText] = token.split(':');
140
+ const pid = Number(pidText);
141
+ if (host !== os.hostname() || !Number.isInteger(pid) || pid <= 0) {
142
+ return false;
143
+ }
144
+ try {
145
+ process.kill(pid, 0);
146
+ return false; // still running
147
+ }
148
+ catch (error) {
149
+ return error.code === 'ESRCH';
150
+ }
151
+ }
152
+ /**
153
+ * Run `fn` holding `<tafPath>.lock`, so two runs that finish together each add
154
+ * their receipt instead of one overwriting the other.
155
+ *
156
+ * The lock holds `host:pid:random`. A stale lock (its owner has exited) is
157
+ * removed by one waiter at a time: the one holding `<lock>.takeover`, which
158
+ * re-reads the lock first and removes it only if it is still the stale one.
159
+ * Nobody else can change the lock meanwhile (writers wait for it; only a
160
+ * takeover removes it), so a live lock is never removed. The lock is released
161
+ * only by its owner.
162
+ */
163
+ function withTafLock(tafPath, fn) {
164
+ const lock = `${tafPath}.lock`;
165
+ const token = `${os.hostname()}:${process.pid}:${Math.random().toString(36).slice(2)}`;
166
+ const deadline = Date.now() + LOCK_WAIT_MS;
167
+ for (;;) {
168
+ try {
169
+ fs.writeFileSync(lock, token, { flag: 'wx' });
170
+ break;
171
+ }
172
+ catch (error) {
173
+ if (error.code !== 'EEXIST') {
174
+ throw error;
175
+ }
176
+ }
177
+ const seen = readFileOrNull(lock);
178
+ if (seen !== null && lockIsStale(seen, lock)) {
179
+ takeOverStaleLock(lock, seen, token);
180
+ continue;
181
+ }
182
+ if (Date.now() > deadline) {
183
+ throw new Error(`${lock} is held by another run (waited ${LOCK_WAIT_MS / 1000}s)`);
184
+ }
185
+ sleep(20 + Math.floor(Math.random() * 30));
186
+ }
187
+ try {
188
+ return fn();
189
+ }
190
+ finally {
191
+ if (readFileOrNull(lock) === token) {
192
+ fs.rmSync(lock, { force: true });
193
+ }
194
+ }
195
+ }
196
+ /** Remove `lock` if it still holds the stale `seen` token, as the one waiter holding `<lock>.takeover`. */
197
+ function takeOverStaleLock(lock, seen, token) {
198
+ const takeover = `${lock}.takeover`;
199
+ try {
200
+ fs.writeFileSync(takeover, token, { flag: 'wx' });
201
+ }
202
+ catch (error) {
203
+ if (error.code !== 'EEXIST') {
204
+ throw error;
205
+ }
206
+ // Another waiter is taking over; clear its claim only if it died doing so.
207
+ const claim = readFileOrNull(takeover);
208
+ if (claim !== null && lockIsStale(claim, takeover)) {
209
+ try {
210
+ if (readFileOrNull(takeover) === claim) {
211
+ fs.rmSync(takeover, { force: true });
212
+ }
213
+ }
214
+ catch {
215
+ // gone already
216
+ }
217
+ }
218
+ sleep(10 + Math.floor(Math.random() * 20));
219
+ return;
220
+ }
221
+ try {
222
+ if (readFileOrNull(lock) === seen) {
223
+ fs.rmSync(lock, { force: true });
224
+ }
225
+ }
226
+ finally {
227
+ if (readFileOrNull(takeover) === token) {
228
+ fs.rmSync(takeover, { force: true });
229
+ }
230
+ }
231
+ }
232
+ /**
233
+ * Write to a temp file beside the real file, then rename it over: a reader
234
+ * never sees half a file. A symlinked .taf stays a symlink (the target is
235
+ * replaced), and the file keeps its mode.
236
+ */
237
+ function writeAtomically(file, text) {
238
+ const target = fs.existsSync(file) ? fs.realpathSync(file) : file;
239
+ const mode = fs.existsSync(target) ? fs.statSync(target).mode & 0o777 : undefined;
240
+ const tmp = path.join(path.dirname(target), `.${path.basename(target)}.${process.pid}.${Date.now()}.tmp`);
241
+ fs.writeFileSync(tmp, text, { encoding: 'utf-8', ...(mode !== undefined ? { mode } : {}) });
242
+ if (mode !== undefined) {
243
+ fs.chmodSync(tmp, mode);
244
+ }
245
+ try {
246
+ fs.renameSync(tmp, target);
247
+ }
248
+ catch (error) {
249
+ fs.rmSync(tmp, { force: true });
250
+ throw error;
251
+ }
252
+ }
253
+ /**
254
+ * What fired the run: GitHub Actions, another CI, or a local run
255
+ */
256
+ function runTrigger(env = process.env) {
257
+ if (env.GITHUB_ACTIONS === 'true')
258
+ return 'github-actions';
259
+ if (env.CI && env.CI !== 'false')
260
+ return 'ci';
261
+ return 'local';
262
+ }
263
+ /**
264
+ * The error when there is no .taf to append to, with the command that makes one
265
+ */
266
+ exports.NO_TAF_FILE = "No .taf file found. Create one: echo 'test_history: []' > .taf";
267
+ /**
268
+ * Create a new TAF file structure
269
+ */
270
+ function createTAF(projectName) {
271
+ return {
272
+ format_version: '1.0.0',
273
+ project: projectName,
274
+ created: new Date().toISOString(),
275
+ last_updated: new Date().toISOString(),
276
+ test_history: [],
277
+ };
278
+ }
279
+ /**
280
+ * The receipts document of a .taf (the first YAML document), and the source
281
+ * text after it: later `---` documents, kept byte for byte whatever they hold.
282
+ */
283
+ function readTaf(content) {
284
+ const tokens = [...new yaml.Parser().parse(content)];
285
+ const first = tokens.findIndex((t) => t.type === 'document');
286
+ if (first === -1) {
287
+ throw new Error('Invalid .taf file: not a valid YAML object');
288
+ }
289
+ const end = tokens[first + 1]?.offset ?? content.length;
290
+ const doc = yaml.parseDocument(content.slice(0, end));
291
+ if (doc.errors.length > 0) {
292
+ throw new Error(`Invalid .taf file: ${doc.errors[0].message}`);
293
+ }
294
+ const parsed = doc.toJS();
295
+ if (!parsed || typeof parsed !== 'object') {
296
+ throw new Error('Invalid .taf file: not a valid YAML object');
297
+ }
298
+ if (!parsed.test_history || !Array.isArray(parsed.test_history)) {
299
+ throw new Error('Invalid .taf file: missing or invalid test_history');
300
+ }
301
+ return { doc, tail: content.slice(end) };
302
+ }
303
+ //# sourceMappingURL=taf-core.js.map