robisie 0.1.4 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +39 -11
- package/dist/agents.d.ts +1 -1
- package/dist/agents.js +1 -1
- package/dist/ci-failure-result.js +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +45 -8
- package/dist/codex-env.d.ts +9 -0
- package/dist/codex-env.js +60 -0
- package/dist/commands.js +145 -16
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/delivery-local.d.ts +124 -0
- package/dist/delivery-local.js +286 -0
- package/dist/disk-guard.d.ts +20 -0
- package/dist/disk-guard.js +63 -0
- package/dist/done-evidence.d.ts +25 -1
- package/dist/done-evidence.js +59 -1
- package/dist/engine/bundle-report.json +1687 -0
- package/dist/engine/tick.cjs +324787 -0
- package/dist/engine-config.d.ts +3 -1
- package/dist/engine-config.js +3 -3
- package/dist/factory-run.d.ts +17 -0
- package/dist/factory-run.js +262 -0
- package/dist/helpers.js +1 -1
- package/dist/k3-codex-job.d.ts +49 -0
- package/dist/k3-codex-job.js +324 -0
- package/dist/k3-codex-role.js +4 -1
- package/dist/k3-helper-cli.d.ts +5 -0
- package/dist/k3-helper-cli.js +193 -0
- package/dist/local-usage.d.ts +47 -0
- package/dist/local-usage.js +230 -0
- package/dist/manifest.d.ts +5 -2
- package/dist/manifest.js +6 -6
- package/dist/planer-client.d.ts +45 -4
- package/dist/planer-client.js +120 -14
- package/dist/roles.d.ts +1 -1
- package/dist/select-fingerprint.d.ts +19 -0
- package/dist/select-fingerprint.js +46 -0
- package/dist/test-report.d.ts +9 -0
- package/dist/test-report.js +139 -0
- package/dist/tester-result-reader.d.ts +87 -0
- package/dist/tester-result-reader.js +122 -0
- package/docs/ENGINE-API.md +9 -1
- package/docs/README.en.md +58 -17
- package/docs/README.md +56 -17
- package/docs/RELEASE-0.1.0.md +28 -5
- package/helpers/ceo-client-launcher-mcp.mjs +76 -5
- package/package.json +6 -2
- package/roles/ceo-client.md +10 -8
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function selectFingerprint(model: string, prompt: string): string;
|
|
2
|
+
export declare function readSelectFingerprint(file: string): string | null;
|
|
3
|
+
export declare function writeSelectFingerprint(file: string, fingerprint: string): void;
|
|
4
|
+
export declare function askUnlessUnchanged<T>(opts: {
|
|
5
|
+
model: string;
|
|
6
|
+
prompt: string;
|
|
7
|
+
file: string;
|
|
8
|
+
force: boolean;
|
|
9
|
+
ask: (prompt: string) => Promise<T>;
|
|
10
|
+
log: (line: string) => void;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
skipped: true;
|
|
13
|
+
fingerprint: string;
|
|
14
|
+
} | {
|
|
15
|
+
skipped: false;
|
|
16
|
+
fingerprint: string;
|
|
17
|
+
value: T;
|
|
18
|
+
commit: () => void;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
export function selectFingerprint(model, prompt) {
|
|
4
|
+
return createHash("sha256").update(`${model}\n${prompt}`).digest("hex");
|
|
5
|
+
}
|
|
6
|
+
export function readSelectFingerprint(file) {
|
|
7
|
+
try {
|
|
8
|
+
return readFileSync(file, "utf8").trim();
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.code === "ENOENT")
|
|
12
|
+
return null;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function writeSelectFingerprint(file, fingerprint) {
|
|
17
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
18
|
+
try {
|
|
19
|
+
writeFileSync(temporary, fingerprint);
|
|
20
|
+
renameSync(temporary, file);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
try {
|
|
24
|
+
unlinkSync(temporary);
|
|
25
|
+
}
|
|
26
|
+
catch (cleanupError) {
|
|
27
|
+
if (cleanupError.code !== "ENOENT")
|
|
28
|
+
throw cleanupError;
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function askUnlessUnchanged(opts) {
|
|
34
|
+
const fingerprint = selectFingerprint(opts.model, opts.prompt);
|
|
35
|
+
if (!opts.force && readSelectFingerprint(opts.file) === fingerprint) {
|
|
36
|
+
opts.log(`selector: skip — input unchanged (fingerprint ${fingerprint})`);
|
|
37
|
+
return { skipped: true, fingerprint };
|
|
38
|
+
}
|
|
39
|
+
const value = await opts.ask(opts.prompt);
|
|
40
|
+
return {
|
|
41
|
+
skipped: false,
|
|
42
|
+
fingerprint,
|
|
43
|
+
value,
|
|
44
|
+
commit: () => writeSelectFingerprint(opts.file, fingerprint),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function passedVitestReport(value: unknown, evidence?: {
|
|
2
|
+
root: string;
|
|
3
|
+
paths: string[];
|
|
4
|
+
skipped: string[];
|
|
5
|
+
reason: string;
|
|
6
|
+
testNamePattern?: RegExp;
|
|
7
|
+
}): boolean;
|
|
8
|
+
export declare function vitestReportPath(name: unknown, root: string): string | null;
|
|
9
|
+
export declare function timeoutVitestFiles(value: unknown, root: string): string[] | null;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function passedVitestReport(value, evidence) {
|
|
4
|
+
const r = asRecord(value);
|
|
5
|
+
if (r.success !== true || !positiveInteger(r.numTotalTestSuites) || !positiveInteger(r.numTotalTests) || r.numFailedTests !== 0 || !Number.isSafeInteger(r.numPendingTests) || Number(r.numPendingTests) < 0
|
|
6
|
+
|| r.numTodoTests !== 0 || r.numFailedTestSuites !== 0 || r.numPendingTestSuites !== 0
|
|
7
|
+
|| !Number.isSafeInteger(r.numPassedTests) || Number(r.numPassedTests) < 0 || Number(r.numPassedTests) + Number(r.numPendingTests) !== r.numTotalTests || r.numPassedTestSuites !== r.numTotalTestSuites
|
|
8
|
+
|| !Array.isArray(r.testResults) || !r.testResults.length)
|
|
9
|
+
return false;
|
|
10
|
+
let count = 0, filtered = 0;
|
|
11
|
+
const skipped = [];
|
|
12
|
+
const valid = r.testResults.every(v => {
|
|
13
|
+
const f = asRecord(v);
|
|
14
|
+
if (!nonempty(f.name) || f.status !== "passed" || f.message !== "" || !Array.isArray(f.assertionResults))
|
|
15
|
+
return false;
|
|
16
|
+
const name = f.name;
|
|
17
|
+
return f.assertionResults.every(v => {
|
|
18
|
+
const t = asRecord(v);
|
|
19
|
+
count++;
|
|
20
|
+
if (!Array.isArray(t.failureMessages) || t.failureMessages.length)
|
|
21
|
+
return false;
|
|
22
|
+
if (t.status === "passed")
|
|
23
|
+
return true;
|
|
24
|
+
if (t.status !== "skipped" || !nonempty(t.fullName) || !evidence?.paths.length)
|
|
25
|
+
return false;
|
|
26
|
+
const rel = posix.relative(evidence.root, path.resolve(evidence.root, name));
|
|
27
|
+
if (!rel || rel.startsWith("../"))
|
|
28
|
+
return false;
|
|
29
|
+
// Vitest's JSON reporter omits the final separator for an empty test title.
|
|
30
|
+
const fullName = t.title === "" ? `${t.fullName} ` : t.fullName;
|
|
31
|
+
if (evidence.testNamePattern && !evidence.testNamePattern.test(fullName)) {
|
|
32
|
+
filtered++;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const identity = JSON.stringify([rel, t.fullName]);
|
|
36
|
+
if (scopesOverlap([rel], evidence.paths)) {
|
|
37
|
+
evidence.reason = `Pominięcie w zakresie karty: ${identity}`;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
skipped.push(identity);
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
}) && count === r.numTotalTests && skipped.length + filtered === r.numPendingTests;
|
|
44
|
+
if (valid && filtered > 0 && r.numPassedTests === 0 && evidence) {
|
|
45
|
+
evidence.reason = "Filtr nazwy nie wybrał żadnego testu";
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (valid)
|
|
49
|
+
evidence?.skipped.push(...skipped);
|
|
50
|
+
return valid;
|
|
51
|
+
}
|
|
52
|
+
export function vitestReportPath(name, root) {
|
|
53
|
+
if (!nonempty(name) || /[\r\n\0\\]/.test(name) || name.split("/").includes(".."))
|
|
54
|
+
return null;
|
|
55
|
+
const rel = path.relative(root, path.resolve(root, name));
|
|
56
|
+
return rel && !rel.startsWith("-") && !rel.startsWith("../") && !path.isAbsolute(rel) ? rel : null;
|
|
57
|
+
}
|
|
58
|
+
export function timeoutVitestFiles(value, root) {
|
|
59
|
+
const report = asRecord(value);
|
|
60
|
+
const counts = ["numTotalTests", "numPassedTests", "numFailedTests", "numPendingTests", "numTodoTests",
|
|
61
|
+
"numTotalTestSuites", "numPassedTestSuites", "numFailedTestSuites", "numPendingTestSuites"];
|
|
62
|
+
if (!counts.every(k => Number.isSafeInteger(report[k]) && Number(report[k]) >= 0)
|
|
63
|
+
|| !positiveInteger(report.numTotalTests) || !positiveInteger(report.numFailedTestSuites)
|
|
64
|
+
|| report.success !== false || report.numPendingTestSuites !== 0
|
|
65
|
+
|| Number(report.numTotalTests) !== Number(report.numPassedTests) + Number(report.numFailedTests) + Number(report.numPendingTests) + Number(report.numTodoTests)
|
|
66
|
+
|| Number(report.numTotalTestSuites) !== Number(report.numPassedTestSuites) + Number(report.numFailedTestSuites)
|
|
67
|
+
|| !Array.isArray(report.testResults) || !report.testResults.length)
|
|
68
|
+
return null;
|
|
69
|
+
const timeout = (message, duration) => typeof message === "string" && (/^(?:Error: )?(?:Test|Hook) timed out in \d+ms\.(?:\s|$)/.test(message)
|
|
70
|
+
|| message.split(/\r?\n/, 1)[0] === "Error: STACK_TRACE_ERROR"
|
|
71
|
+
&& typeof duration === "number" && Number.isFinite(duration) && duration >= 30_000);
|
|
72
|
+
if (report.numRuntimeErrorTestSuites != null && report.numRuntimeErrorTestSuites !== 0
|
|
73
|
+
|| report.unhandledErrors != null && (!Array.isArray(report.unhandledErrors) || report.unhandledErrors.length))
|
|
74
|
+
return null;
|
|
75
|
+
const paths = [];
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
let failed = 0, passed = 0, pending = 0, todo = 0, total = 0, failedFiles = 0;
|
|
78
|
+
for (const entry of report.testResults) {
|
|
79
|
+
const file = asRecord(entry);
|
|
80
|
+
if (!nonempty(file.name) || !Array.isArray(file.assertionResults) || !["passed", "failed"].includes(String(file.status)))
|
|
81
|
+
return null;
|
|
82
|
+
const rel = vitestReportPath(file.name, root);
|
|
83
|
+
if (!rel || seen.has(rel) || !file.assertionResults.length)
|
|
84
|
+
return null;
|
|
85
|
+
seen.add(rel);
|
|
86
|
+
let red = false;
|
|
87
|
+
if (file.message !== "") {
|
|
88
|
+
if (!timeout(file.message, file.duration))
|
|
89
|
+
return null;
|
|
90
|
+
red = true;
|
|
91
|
+
}
|
|
92
|
+
for (const item of file.assertionResults) {
|
|
93
|
+
const test = asRecord(item);
|
|
94
|
+
total++;
|
|
95
|
+
if (!["passed", "failed", "skipped", "pending", "todo"].includes(String(test.status)))
|
|
96
|
+
return null;
|
|
97
|
+
if (test.status === "failed") {
|
|
98
|
+
failed++;
|
|
99
|
+
red = true;
|
|
100
|
+
if (!Array.isArray(test.failureMessages) || !test.failureMessages.length || !test.failureMessages.every(message => timeout(message, test.duration)))
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (!Array.isArray(test.failureMessages) || test.failureMessages.length)
|
|
105
|
+
return null;
|
|
106
|
+
if (test.status === "passed")
|
|
107
|
+
passed++;
|
|
108
|
+
else if (test.status === "todo")
|
|
109
|
+
todo++;
|
|
110
|
+
else
|
|
111
|
+
pending++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if ((file.status === "failed") !== red)
|
|
115
|
+
return null;
|
|
116
|
+
if (red) {
|
|
117
|
+
failedFiles++;
|
|
118
|
+
paths.push(rel);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return paths.length && total === report.numTotalTests && failed === report.numFailedTests
|
|
122
|
+
&& passed === report.numPassedTests && pending === report.numPendingTests && todo === report.numTodoTests
|
|
123
|
+
&& Number(report.numFailedTestSuites) >= failedFiles && Number(report.numPassedTestSuites) >= seen.size - failedFiles ? paths : null;
|
|
124
|
+
}
|
|
125
|
+
function scopesOverlap(a, b) {
|
|
126
|
+
return a.some(x => b.some(y => x === "." || y === "." || x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`)));
|
|
127
|
+
}
|
|
128
|
+
function record(value) {
|
|
129
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
130
|
+
}
|
|
131
|
+
function asRecord(value) {
|
|
132
|
+
return record(value) ? value : {};
|
|
133
|
+
}
|
|
134
|
+
function positiveInteger(value) {
|
|
135
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
136
|
+
}
|
|
137
|
+
function nonempty(value) {
|
|
138
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
139
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export type CardLike = {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
status?: string | null;
|
|
5
|
+
details?: Record<string, unknown> | null;
|
|
6
|
+
};
|
|
7
|
+
export type TesterExecution = {
|
|
8
|
+
sha: string;
|
|
9
|
+
at: string;
|
|
10
|
+
commands: string[];
|
|
11
|
+
reversible: boolean;
|
|
12
|
+
notLanded: boolean;
|
|
13
|
+
base: string | null;
|
|
14
|
+
failed: {
|
|
15
|
+
command: string;
|
|
16
|
+
output: string;
|
|
17
|
+
} | null;
|
|
18
|
+
testedHead: string;
|
|
19
|
+
incomplete: boolean;
|
|
20
|
+
timeoutPaths: string[];
|
|
21
|
+
skippedTests: string[];
|
|
22
|
+
transcript: string;
|
|
23
|
+
retest?: TesterRetestGrant | null;
|
|
24
|
+
baselineFailures?: {
|
|
25
|
+
command: string;
|
|
26
|
+
sha: string;
|
|
27
|
+
tests: string[];
|
|
28
|
+
ref: string;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
export declare function validTestSha(value: unknown): value is string;
|
|
32
|
+
export declare function landedSha(card: CardLike): string | null;
|
|
33
|
+
export declare const AUTOMATIC_TESTER_RETEST_DECISION = "automat TESTER-RETEST-POZA-ZAKRESEM (DL S-TESTER-RETEST)";
|
|
34
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
35
|
+
export type TesterRetestGrant = {
|
|
36
|
+
sha: string;
|
|
37
|
+
at: string;
|
|
38
|
+
reason: string;
|
|
39
|
+
decision: string;
|
|
40
|
+
};
|
|
41
|
+
export type TesterHistoricalRecovery = {
|
|
42
|
+
recovery: "missing-report" | "missing-json" | "legacy-times" | "legacy-base" | "foreign-report";
|
|
43
|
+
};
|
|
44
|
+
export type TesterQualification = TesterRetestGrant | TesterHistoricalRecovery | null;
|
|
45
|
+
export type TesterQualifications = {
|
|
46
|
+
qualifications: TesterQualification[];
|
|
47
|
+
};
|
|
48
|
+
export type TesterJobInput = {
|
|
49
|
+
card: CardLike;
|
|
50
|
+
runtime: string;
|
|
51
|
+
qualify?: CardLike[];
|
|
52
|
+
};
|
|
53
|
+
export type Packet = {
|
|
54
|
+
version: 1;
|
|
55
|
+
id: string;
|
|
56
|
+
input: TesterJobInput;
|
|
57
|
+
};
|
|
58
|
+
export type TesterCompletion = Packet & {
|
|
59
|
+
result?: TesterExecution;
|
|
60
|
+
qualifications?: TesterQualification[];
|
|
61
|
+
error?: string;
|
|
62
|
+
};
|
|
63
|
+
export type Poll = {
|
|
64
|
+
kind: "idle";
|
|
65
|
+
} | {
|
|
66
|
+
kind: "running";
|
|
67
|
+
pid: number;
|
|
68
|
+
} | {
|
|
69
|
+
kind: "complete";
|
|
70
|
+
completion: TesterCompletion;
|
|
71
|
+
} | {
|
|
72
|
+
kind: "failed";
|
|
73
|
+
id: string;
|
|
74
|
+
error: string;
|
|
75
|
+
};
|
|
76
|
+
export declare const files: (dir: string) => {
|
|
77
|
+
lock: string;
|
|
78
|
+
input: string;
|
|
79
|
+
result: string;
|
|
80
|
+
};
|
|
81
|
+
export declare const record: (value: unknown) => Record<string, unknown>;
|
|
82
|
+
export declare function readJson(file: string): unknown;
|
|
83
|
+
export declare function packet(value: unknown): Packet;
|
|
84
|
+
export declare function retestGrant(value: unknown, card: CardLike): TesterRetestGrant | null;
|
|
85
|
+
export declare function qualifications(value: unknown, input: TesterJobInput): TesterQualification[];
|
|
86
|
+
export declare function execution(value: unknown, input: TesterJobInput): TesterExecution;
|
|
87
|
+
export declare function readTesterJob(dir: string): Poll;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export function validTestSha(value) {
|
|
5
|
+
return typeof value === "string" && /^[a-f0-9]{7,40}$/i.test(value);
|
|
6
|
+
}
|
|
7
|
+
export function landedSha(card) {
|
|
8
|
+
const landed = card.details?.landed;
|
|
9
|
+
return isRecord(landed) && validTestSha(landed.sha) ? landed.sha : null;
|
|
10
|
+
}
|
|
11
|
+
export const AUTOMATIC_TESTER_RETEST_DECISION = "automat TESTER-RETEST-POZA-ZAKRESEM (DL S-TESTER-RETEST)";
|
|
12
|
+
export function isRecord(value) {
|
|
13
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
export const files = (dir) => ({ lock: path.join(dir, ".tester-job.lock"), input: path.join(dir, ".tester-job.input.json"), result: path.join(dir, ".tester-job.result.json") });
|
|
16
|
+
export const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
17
|
+
export function readJson(file) {
|
|
18
|
+
try {
|
|
19
|
+
if (!existsSync(file))
|
|
20
|
+
return undefined;
|
|
21
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code === "ENOENT")
|
|
25
|
+
return undefined;
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function packet(value) {
|
|
30
|
+
const p = record(value), input = record(p.input), card = record(input.card);
|
|
31
|
+
if (p.version !== 1 || typeof p.id !== "string" || !p.id || typeof input.runtime !== "string"
|
|
32
|
+
|| typeof card.id !== "string" || !card.id || !["delivered", "blocked"].includes(String(card.status))
|
|
33
|
+
|| !validTestSha(landedSha(card)))
|
|
34
|
+
throw new Error("Niepoprawna tożsamość joba testera");
|
|
35
|
+
if (input.qualify !== undefined && (!Array.isArray(input.qualify) || !input.qualify.length
|
|
36
|
+
|| !isDeepStrictEqual(input.qualify[0], input.card)
|
|
37
|
+
|| new Set(input.qualify.map(c => record(c).id)).size !== input.qualify.length
|
|
38
|
+
|| input.qualify.some(c => {
|
|
39
|
+
const row = record(c), details = record(row.details), test = record(details.test);
|
|
40
|
+
return typeof row.id !== "string" || !row.id || row.status !== "blocked" || details.retest != null
|
|
41
|
+
|| !validTestSha(landedSha(row)) || test.verdict !== "FAIL" || test.sha !== landedSha(row);
|
|
42
|
+
})))
|
|
43
|
+
throw new Error("Niepoprawne snapshoty kwalifikacji testera");
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
export function retestGrant(value, card) {
|
|
47
|
+
if (value === null)
|
|
48
|
+
return null;
|
|
49
|
+
const grant = record(value), test = record(card.details?.test);
|
|
50
|
+
if (grant.sha !== landedSha(card) || grant.decision !== AUTOMATIC_TESTER_RETEST_DECISION
|
|
51
|
+
|| typeof grant.reason !== "string" || !grant.reason.trim() || typeof grant.at !== "string"
|
|
52
|
+
|| !Number.isFinite(Date.parse(grant.at)) || !Number.isFinite(Date.parse(String(test.at)))
|
|
53
|
+
|| Date.parse(grant.at) <= Date.parse(String(test.at)))
|
|
54
|
+
throw new Error("Niepoprawny grant testera");
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
export function qualifications(value, input) {
|
|
58
|
+
if (!input.qualify || !Array.isArray(value) || value.length !== input.qualify.length)
|
|
59
|
+
throw new Error("Niepełny wynik kwalifikacji testera");
|
|
60
|
+
return value.map((grant, index) => {
|
|
61
|
+
if (record(grant).recovery !== undefined) {
|
|
62
|
+
const recovery = record(grant).recovery;
|
|
63
|
+
if (Object.keys(record(grant)).length === 1)
|
|
64
|
+
switch (recovery) {
|
|
65
|
+
case "missing-report":
|
|
66
|
+
case "missing-json":
|
|
67
|
+
case "legacy-times":
|
|
68
|
+
case "legacy-base":
|
|
69
|
+
case "foreign-report": return { recovery };
|
|
70
|
+
}
|
|
71
|
+
throw new Error("Niepoprawna kwalifikacja historycznej próby testera");
|
|
72
|
+
}
|
|
73
|
+
return retestGrant(grant, input.qualify[index]);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export function execution(value, input) {
|
|
77
|
+
const r = record(value), strings = (v) => Array.isArray(v) && v.every(x => typeof x === "string");
|
|
78
|
+
const failed = record(r.failed);
|
|
79
|
+
if (r.sha !== landedSha(input.card) || typeof r.at !== "string" || !Number.isFinite(Date.parse(r.at))
|
|
80
|
+
|| !strings(r.commands) || !strings(r.timeoutPaths) || !strings(r.skippedTests)
|
|
81
|
+
|| typeof r.transcript !== "string" || typeof r.reversible !== "boolean" || typeof r.notLanded !== "boolean" || typeof r.incomplete !== "boolean"
|
|
82
|
+
|| !(r.base === null || validTestSha(r.base)) || !(r.testedHead === "UNKNOWN" || validTestSha(r.testedHead))
|
|
83
|
+
|| !(r.failed === null || (typeof failed.command === "string" && typeof failed.output === "string")))
|
|
84
|
+
throw new Error("Niepoprawny wynik joba testera");
|
|
85
|
+
if (r.retest !== undefined)
|
|
86
|
+
retestGrant(r.retest, { ...input.card, details: { ...input.card.details, test: { at: r.at } } });
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
export function readTesterJob(dir) {
|
|
90
|
+
const f = files(dir), raw = readJson(f.lock);
|
|
91
|
+
if (raw === undefined) {
|
|
92
|
+
if (readJson(f.result) !== undefined || readJson(f.input) !== undefined)
|
|
93
|
+
throw new Error("Osierocony wynik testera bez locka — HOLD");
|
|
94
|
+
return { kind: "idle" };
|
|
95
|
+
}
|
|
96
|
+
const lock = record(raw);
|
|
97
|
+
if (typeof lock.id !== "string" || !Number.isSafeInteger(lock.pid) || Number(lock.pid) <= 0
|
|
98
|
+
|| typeof lock.starting !== "boolean" || typeof lock.createdAt !== "number")
|
|
99
|
+
throw new Error("Nieczytelny lock testera — HOLD");
|
|
100
|
+
const result = readJson(f.result);
|
|
101
|
+
if (result !== undefined) {
|
|
102
|
+
const completed = packet(result), original = packet(readJson(f.input));
|
|
103
|
+
if (completed.id !== lock.id || !isDeepStrictEqual(original, { version: completed.version, id: completed.id, input: completed.input }))
|
|
104
|
+
throw new Error("Obcy wynik testera — HOLD");
|
|
105
|
+
const error = record(result).error;
|
|
106
|
+
if (typeof error === "string" && error)
|
|
107
|
+
return { kind: "complete", completion: { ...completed, error } };
|
|
108
|
+
if (completed.input.qualify)
|
|
109
|
+
return { kind: "complete", completion: { ...completed, qualifications: qualifications(record(result).qualifications, completed.input) } };
|
|
110
|
+
return { kind: "complete", completion: { ...completed, result: execution(record(result).result, completed.input) } };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
process.kill(Number(lock.pid), 0);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error.code !== "ESRCH")
|
|
117
|
+
return { kind: "running", pid: Number(lock.pid) }; // EPERM is not proof of death.
|
|
118
|
+
if (!lock.starting || Date.now() - lock.createdAt > 30_000)
|
|
119
|
+
return { kind: "failed", id: lock.id, error: "Tester zakończył się bez pliku wyniku" };
|
|
120
|
+
}
|
|
121
|
+
return { kind: "running", pid: Number(lock.pid) };
|
|
122
|
+
}
|
package/docs/ENGINE-API.md
CHANGED
|
@@ -85,4 +85,12 @@ Serwer stosuje **płytki merge**: patch zastępuje całą wartość pod wskazany
|
|
|
85
85
|
|
|
86
86
|
Osobna operacja `updateTask({ id, status: 'ready', expected: { status: 'draft' } })` przekazuje warunek oczekiwanego statusu. Warunek, przejście statusu i uprawnienia rozstrzyga serwer; SDK nie implementuje własnego CAS. Powyższe przykłady nie wykonują update.
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
## Operacje silnika
|
|
89
|
+
|
|
90
|
+
Te operacje działają już na kontrakcie `1.0.0`: karta z `getTask`/`listTasks` zawiera też `updatedAt`, `createdAt` i `specRef`; `moveTask({ id, trackId })` przenosi kartę (podaj co najmniej jedno z `trackId`, `afterId`, `beforeId`); `createTrack` i `createTask` tworzą tor i kartę na jawne polecenie callera.
|
|
91
|
+
|
|
92
|
+
### Wymagają kontraktu serwera ≥ 1.1.0
|
|
93
|
+
|
|
94
|
+
Tylko trzy operacje wymagają serwera z kontraktem co najmniej `1.1.0`: `updateTask` z `expected.details` lub `detailsPatch`, `appendDetailIf({ id, patch, expected: { key, value?, status?, details? } })` oraz `writeDecisionMatter({ id, matterId, patch, expected? })`. Starszy serwer po cichu pominąłby nieznane pola i zapisałby bez warunku, dlatego SDK odmawia lokalnie, przed wysłaniem, błędem `UNSUPPORTED_CONTRACT` (`uncertain === false`). `appendDetailIf` zwraca `{ applied: false }` tylko przy jawnym konflikcie tej karty; brak `value` oznacza „klucza nie ma”, a `value: null` literalne `null`. `writeDecisionMatter` zwraca zapisany stan sprawy (także gdy serwer odmówił zmiany) albo `null`; caller sam go porównuje. Żadna z tych operacji nie ponawia zapisu.
|
|
95
|
+
|
|
96
|
+
SDK nie tworzy projektu; tor i kartę tworzy wyłącznie jawne wywołanie `createTrack`/`createTask` przez callera. SDK nie nadaje uprawnień, nie dowodzi odbioru `done` i nie uruchamia silnika. Potwierdzenie append nie jest dowodem wykonania zadania ani niezależnej recenzji. Role, odbiór i uruchomienie pracy wymagają ich własnych kontraktów.
|