agent-steward 0.0.4 → 0.0.6
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 +309 -2
- package/CROSS_PLATFORM.md +19 -0
- package/README.md +55 -8
- package/ROADMAP-STRATEGY.md +22 -19
- package/ROADMAP.md +230 -159
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +356 -0
- package/dist/core/analytics.d.ts +6 -0
- package/dist/core/analytics.d.ts.map +1 -1
- package/dist/core/analytics.js +20 -3
- package/dist/core/audit.d.ts +6 -0
- package/dist/core/audit.d.ts.map +1 -1
- package/dist/core/audit.js +24 -0
- package/dist/core/budget.d.ts +118 -0
- package/dist/core/budget.d.ts.map +1 -0
- package/dist/core/budget.js +206 -0
- package/dist/core/cron-to-schtasks.d.ts.map +1 -1
- package/dist/core/cron-to-schtasks.js +38 -0
- package/dist/core/dry-run.d.ts +26 -1
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +199 -8
- package/dist/core/execution.d.ts +203 -0
- package/dist/core/execution.d.ts.map +1 -0
- package/dist/core/execution.js +309 -0
- package/dist/core/feedback.d.ts +192 -0
- package/dist/core/feedback.d.ts.map +1 -0
- package/dist/core/feedback.js +426 -0
- package/dist/core/gate-integrity.d.ts +71 -0
- package/dist/core/gate-integrity.d.ts.map +1 -0
- package/dist/core/gate-integrity.js +275 -0
- package/dist/core/git-trigger.d.ts.map +1 -1
- package/dist/core/git-trigger.js +14 -2
- package/dist/core/guard-run.d.ts +4 -0
- package/dist/core/guard-run.d.ts.map +1 -0
- package/dist/core/guard-run.js +101 -0
- package/dist/core/guard.d.ts +52 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +362 -0
- package/dist/core/local-ai.d.ts.map +1 -1
- package/dist/core/local-ai.js +7 -3
- package/dist/core/lock.d.ts +41 -0
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +141 -29
- package/dist/core/matrix.d.ts +8 -0
- package/dist/core/matrix.d.ts.map +1 -1
- package/dist/core/matrix.js +132 -17
- package/dist/core/mission.d.ts +103 -0
- package/dist/core/mission.d.ts.map +1 -0
- package/dist/core/mission.js +374 -0
- package/dist/core/opencode-models.d.ts +2 -2
- package/dist/core/opencode-models.d.ts.map +1 -1
- package/dist/core/opencode-models.js +28 -21
- package/dist/core/opencode-usage.d.ts +35 -0
- package/dist/core/opencode-usage.d.ts.map +1 -0
- package/dist/core/opencode-usage.js +132 -0
- package/dist/core/pipeline-apply.d.ts +38 -0
- package/dist/core/pipeline-apply.d.ts.map +1 -0
- package/dist/core/pipeline-apply.js +117 -0
- package/dist/core/pipeline-io.d.ts +13 -0
- package/dist/core/pipeline-io.d.ts.map +1 -0
- package/dist/core/pipeline-io.js +78 -0
- package/dist/core/pipeline-map.d.ts +52 -0
- package/dist/core/pipeline-map.d.ts.map +1 -0
- package/dist/core/pipeline-map.js +208 -0
- package/dist/core/pipeline-spec.d.ts +109 -0
- package/dist/core/pipeline-spec.d.ts.map +1 -0
- package/dist/core/pipeline-spec.js +554 -0
- package/dist/core/ps-wrapper.d.ts +27 -2
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +424 -65
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +206 -33
- package/dist/core/router/rules.d.ts.map +1 -1
- package/dist/core/router/rules.js +6 -0
- package/dist/core/run-mode.d.ts +12 -0
- package/dist/core/run-mode.d.ts.map +1 -0
- package/dist/core/run-mode.js +17 -0
- package/dist/core/scheduler/linux.d.ts +8 -1
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +34 -9
- package/dist/core/scheduler/logs.d.ts +4 -0
- package/dist/core/scheduler/logs.d.ts.map +1 -1
- package/dist/core/scheduler/logs.js +25 -1
- package/dist/core/scheduler/mac.d.ts +44 -2
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +126 -15
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +15 -12
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +18 -8
- package/dist/core/self-analysis.d.ts +32 -2
- package/dist/core/self-analysis.d.ts.map +1 -1
- package/dist/core/self-analysis.js +38 -27
- package/dist/core/shutdown.d.ts +33 -2
- package/dist/core/shutdown.d.ts.map +1 -1
- package/dist/core/shutdown.js +58 -2
- package/dist/core/structured-log.d.ts +37 -1
- package/dist/core/structured-log.d.ts.map +1 -1
- package/dist/core/structured-log.js +37 -0
- package/dist/core/usage-surface.d.ts +25 -0
- package/dist/core/usage-surface.d.ts.map +1 -0
- package/dist/core/usage-surface.js +41 -0
- package/dist/core/worktree-run.d.ts +4 -0
- package/dist/core/worktree-run.d.ts.map +1 -0
- package/dist/core/worktree-run.js +164 -0
- package/dist/core/worktree.d.ts +115 -0
- package/dist/core/worktree.d.ts.map +1 -0
- package/dist/core/worktree.js +462 -0
- package/dist/core/wrappers/bash.d.ts +19 -0
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +230 -27
- package/dist/db/capability-repo.d.ts +43 -2
- package/dist/db/capability-repo.d.ts.map +1 -1
- package/dist/db/capability-repo.js +96 -11
- package/dist/db/history-repo.d.ts +70 -5
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +170 -29
- package/dist/db/metrics-repo.d.ts +20 -2
- package/dist/db/metrics-repo.d.ts.map +1 -1
- package/dist/db/metrics-repo.js +35 -13
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +37 -17
- package/dist/db/recovery.d.ts +3 -1
- package/dist/db/recovery.d.ts.map +1 -1
- package/dist/db/recovery.js +11 -5
- package/dist/db/run-journal.d.ts +33 -5
- package/dist/db/run-journal.d.ts.map +1 -1
- package/dist/db/run-journal.js +78 -14
- package/dist/db/run-resume.d.ts +5 -0
- package/dist/db/run-resume.d.ts.map +1 -1
- package/dist/db/run-resume.js +9 -2
- package/dist/db/runs-repo.d.ts +19 -2
- package/dist/db/runs-repo.d.ts.map +1 -1
- package/dist/db/runs-repo.js +91 -60
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +132 -2
- package/dist/db/templates-repo.d.ts +2 -2
- package/dist/db/templates-repo.d.ts.map +1 -1
- package/dist/db/templates-repo.js +5 -3
- package/dist/history.d.ts +7 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +4 -2
- package/dist/hook-output.d.ts +2 -0
- package/dist/hook-output.d.ts.map +1 -0
- package/dist/hook-output.js +31 -0
- package/dist/i18n.d.ts +5 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +11 -4
- package/dist/index.d.ts +375 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1344 -192
- package/dist/notifications.d.ts +53 -2
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +168 -21
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +82 -10
- package/dist/rpc.d.ts +354 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +145 -0
- package/dist/server.d.ts +32 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +154 -30
- package/dist/settings.d.ts +44 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +85 -3
- package/dist/shared/jobs-view.d.ts +1 -1
- package/dist/shared/jobs-view.d.ts.map +1 -1
- package/dist/shared/jobs-view.js +2 -0
- package/dist/task-transfer.d.ts +21 -0
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +64 -3
- package/dist/templates.d.ts +2 -2
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +3 -3
- package/dist/types.d.ts +22 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +34 -11
- package/docs/ARCHITECTURE.md +319 -66
- package/docs/COMPATIBILITY.md +2 -2
- package/docs/CONCEPT.md +18 -4
- package/docs/CROSS_PLATFORM.ru.md +20 -0
- package/docs/CROSS_PLATFORM.zh.md +18 -0
- package/docs/EXECUTION-LOOP.md +28 -10
- package/docs/FEATURES.md +129 -7
- package/docs/FEATURES.zh.md +97 -6
- package/docs/MIGRATION.md +2 -2
- package/docs/PIPELINE.md +293 -0
- package/docs/QA-A2-GUI-TUI.md +205 -0
- package/docs/README.ru.md +43 -4
- package/docs/README.zh.md +44 -4
- package/docs/SAFETY.md +23 -3
- package/gui-experimental.cjs +9 -8
- package/locales/en.json +58 -3
- package/locales/ru.json +58 -3
- package/locales/zh.json +58 -3
- package/opencode.pipeline.yaml +35 -0
- package/package.json +36 -4
- package/scripts/check-eslint-baseline.mjs +139 -0
- package/scripts/gen-test-plan-counters.mjs +117 -0
- package/scripts/github-ci-fetch.ps1 +37 -0
- package/scripts/pl-commit.ps1 +112 -0
- package/scripts/qa-a2-commit.ps1 +104 -0
- package/scripts/test-home.mjs +107 -0
- package/skills/scheduled-job-best-practices/SKILL.md +95 -1
- package/skills/scheduled-job-best-practices/references/recipes.md +139 -0
- package/src/cli.ts +417 -0
- package/src/core/analytics.ts +27 -4
- package/src/core/audit.ts +25 -0
- package/src/core/budget.ts +340 -0
- package/src/core/cron-to-schtasks.ts +42 -0
- package/src/core/dry-run.ts +235 -12
- package/src/core/execution.ts +538 -0
- package/src/core/feedback.ts +582 -0
- package/src/core/file-watcher.ts +2 -2
- package/src/core/gate-integrity.ts +330 -0
- package/src/core/git-trigger.ts +18 -5
- package/src/core/guard-run.ts +119 -0
- package/src/core/guard.ts +431 -0
- package/src/core/local-ai.ts +7 -3
- package/src/core/lock.ts +178 -37
- package/src/core/matrix.ts +158 -52
- package/src/core/mission.ts +531 -0
- package/src/core/native-notify.ts +1 -1
- package/src/core/opencode-models.ts +30 -21
- package/src/core/opencode-usage.ts +182 -0
- package/src/core/pipeline-apply.ts +158 -0
- package/src/core/pipeline-io.ts +96 -0
- package/src/core/pipeline-map.ts +283 -0
- package/src/core/pipeline-spec.ts +775 -0
- package/src/core/ps-wrapper.ts +435 -66
- package/src/core/record-history.ts +258 -81
- package/src/core/router/rules.ts +6 -0
- package/src/core/run-mode.ts +19 -0
- package/src/core/schedule-gate.ts +1 -1
- package/src/core/scheduler/at-fallback.ts +1 -1
- package/src/core/scheduler/linux.ts +40 -11
- package/src/core/scheduler/logs.ts +34 -3
- package/src/core/scheduler/mac.ts +174 -14
- package/src/core/scheduler/registry.ts +2 -2
- package/src/core/scheduler/windows.ts +19 -15
- package/src/core/secrets.ts +26 -19
- package/src/core/self-analysis.ts +75 -29
- package/src/core/shutdown.ts +90 -4
- package/src/core/structured-log.ts +89 -5
- package/src/core/telegram.ts +2 -2
- package/src/core/triage-worker.ts +7 -7
- package/src/core/triage.ts +2 -2
- package/src/core/usage-surface.ts +70 -0
- package/src/core/worktree-run.ts +199 -0
- package/src/core/worktree.ts +600 -0
- package/src/core/wrappers/bash.ts +248 -26
- package/src/db/capability-repo.ts +127 -10
- package/src/db/history-repo.ts +281 -40
- package/src/db/metrics-repo.ts +40 -13
- package/src/db/migrate.ts +57 -32
- package/src/db/recovery.ts +12 -5
- package/src/db/run-journal.ts +100 -13
- package/src/db/run-resume.ts +17 -1
- package/src/db/runs-repo.ts +147 -65
- package/src/db/schema.ts +134 -2
- package/src/db/templates-repo.ts +5 -3
- package/src/gui.tsx +438 -18
- package/src/history.ts +11 -4
- package/src/hook-output.ts +39 -0
- package/src/i18n.ts +12 -4
- package/src/index.ts +1902 -320
- package/src/notifications.ts +227 -47
- package/src/profiles.ts +88 -10
- package/src/rpc.ts +158 -0
- package/src/server.ts +201 -41
- package/src/settings.ts +125 -5
- package/src/shared/jobs-view.ts +3 -1
- package/src/task-transfer.ts +90 -6
- package/src/templates.ts +3 -3
- package/src/types.ts +23 -2
- package/src/workspaces.ts +37 -14
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QA-A2.0 — храповик (ratchet) для предупреждений ESLint.
|
|
3
|
+
*
|
|
4
|
+
* Сравнивает текущие счётчики `eslint src` с зафиксированными в
|
|
5
|
+
* `eslint-baseline.json` и падает, если где-то появилось НОВОЕ предупреждение.
|
|
6
|
+
* Уменьшения разрешены и по ним baseline обновляется вручную:
|
|
7
|
+
*
|
|
8
|
+
* npm run lint:baseline # проверить (используется в CI)
|
|
9
|
+
* npm run lint:baseline:update # перезаписать baseline после уменьшения
|
|
10
|
+
*
|
|
11
|
+
* Исторический старт эпика QA-A2 — 826 предупреждений; он лежит в поле
|
|
12
|
+
* epicStartWarnings как справка. Гейт сравнивает с актуальными числами:
|
|
13
|
+
* после QA-A2.1 их 543, и каждая следующая подзадача (A2.2-A2.5) опускает
|
|
14
|
+
* планку. Гейт снимается в QA-A2.7.
|
|
15
|
+
*
|
|
16
|
+
* Запуск: node scripts/check-eslint-baseline.mjs [--update]
|
|
17
|
+
*/
|
|
18
|
+
import fs from "node:fs";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import url from "node:url";
|
|
21
|
+
import { ESLint } from "eslint";
|
|
22
|
+
|
|
23
|
+
const root = path.dirname(path.dirname(url.fileURLToPath(import.meta.url)));
|
|
24
|
+
export const baselinePath = path.join(root, "eslint-baseline.json");
|
|
25
|
+
export const EPIC_START_WARNINGS = 826;
|
|
26
|
+
|
|
27
|
+
/** Путь файла в baseline — всегда относительно корня и с прямыми слешами. */
|
|
28
|
+
export function relativePath(filePath) {
|
|
29
|
+
return path.relative(root, filePath).split(path.sep).join("/");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Собирает счётчики из результатов ESLint. Чистая функция — тестируется отдельно. */
|
|
33
|
+
export function collect(results) {
|
|
34
|
+
const byFile = {};
|
|
35
|
+
const byRule = {};
|
|
36
|
+
const byFileRule = {};
|
|
37
|
+
let warnings = 0;
|
|
38
|
+
let errors = 0;
|
|
39
|
+
|
|
40
|
+
for (const result of results) {
|
|
41
|
+
const file = relativePath(result.filePath);
|
|
42
|
+
for (const message of result.messages) {
|
|
43
|
+
if (message.severity === 2) errors += 1;
|
|
44
|
+
else if (message.severity === 1) warnings += 1;
|
|
45
|
+
|
|
46
|
+
const rule = message.ruleId ?? "(fatal)";
|
|
47
|
+
byRule[rule] = (byRule[rule] ?? 0) + 1;
|
|
48
|
+
byFile[file] = (byFile[file] ?? 0) + 1;
|
|
49
|
+
byFileRule[file] ??= {};
|
|
50
|
+
byFileRule[file][rule] = (byFileRule[file][rule] ?? 0) + 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { warnings, errors, byRule, byFile, byFileRule };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Сравнивает текущие счётчики с baseline. Любой рост — регрессия.
|
|
59
|
+
* Уменьшения разрешены и по ним baseline обновляется вручную.
|
|
60
|
+
*/
|
|
61
|
+
export function compare(current, baseline) {
|
|
62
|
+
const problems = [];
|
|
63
|
+
const allowedTotals = baseline.totals ?? { warnings: 0, errors: 0 };
|
|
64
|
+
|
|
65
|
+
if (current.errors > 0) {
|
|
66
|
+
problems.push(`ESLint errors: ${current.errors} (в baseline ${allowedTotals.errors})`);
|
|
67
|
+
}
|
|
68
|
+
if (current.warnings > allowedTotals.warnings) {
|
|
69
|
+
problems.push(
|
|
70
|
+
`всего warning: ${current.warnings} > baseline ${allowedTotals.warnings}`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
for (const [rule, count] of Object.entries(current.byRule ?? {})) {
|
|
74
|
+
const allowed = baseline.byRule?.[rule] ?? 0;
|
|
75
|
+
if (count > allowed) problems.push(`${rule}: ${count} > baseline ${allowed}`);
|
|
76
|
+
}
|
|
77
|
+
for (const [file, count] of Object.entries(current.byFile ?? {})) {
|
|
78
|
+
const allowed = baseline.byFile?.[file] ?? 0;
|
|
79
|
+
if (count > allowed) problems.push(`${file}: ${count} > baseline ${allowed}`);
|
|
80
|
+
}
|
|
81
|
+
for (const [file, rules] of Object.entries(current.byFileRule ?? {})) {
|
|
82
|
+
for (const [rule, count] of Object.entries(rules)) {
|
|
83
|
+
const allowed = baseline.byFileRule?.[file]?.[rule] ?? 0;
|
|
84
|
+
if (count > allowed) {
|
|
85
|
+
problems.push(`${file} [${rule}]: ${count} > baseline ${allowed}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return { ok: problems.length === 0, problems };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Собирает документ baseline из текущих результатов линтера. */
|
|
94
|
+
export function makeBaseline(current) {
|
|
95
|
+
return {
|
|
96
|
+
task: "QA-A2.0",
|
|
97
|
+
epicStartWarnings: EPIC_START_WARNINGS,
|
|
98
|
+
note:
|
|
99
|
+
"Ratchet: новое предупреждение — красный CI. После уменьшения счётчика " +
|
|
100
|
+
"обновить через npm run lint:baseline:update. Гейт снимается в QA-A2.7.",
|
|
101
|
+
totals: { warnings: current.warnings, errors: current.errors },
|
|
102
|
+
byRule: current.byRule,
|
|
103
|
+
byFile: current.byFile,
|
|
104
|
+
byFileRule: current.byFileRule,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const isMain =
|
|
109
|
+
process.argv[1] &&
|
|
110
|
+
path.resolve(process.argv[1]) === url.fileURLToPath(import.meta.url);
|
|
111
|
+
|
|
112
|
+
if (isMain) {
|
|
113
|
+
const eslint = new ESLint();
|
|
114
|
+
const results = await eslint.lintFiles(["src"]);
|
|
115
|
+
const current = collect(results);
|
|
116
|
+
|
|
117
|
+
if (process.argv.includes("--update")) {
|
|
118
|
+
fs.writeFileSync(baselinePath, JSON.stringify(makeBaseline(current), null, 2) + "\n");
|
|
119
|
+
console.log(
|
|
120
|
+
`QA-A2.0: baseline обновлён — ${current.warnings} warning, ${current.errors} error`
|
|
121
|
+
);
|
|
122
|
+
process.exit(0);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const baseline = JSON.parse(fs.readFileSync(baselinePath, "utf8"));
|
|
126
|
+
const { ok, problems } = compare(current, baseline);
|
|
127
|
+
if (ok) {
|
|
128
|
+
const saved = baseline.totals.warnings - current.warnings;
|
|
129
|
+
console.log(
|
|
130
|
+
`QA-A2.0: новых предупреждений нет — ${current.warnings} warning ` +
|
|
131
|
+
`(baseline ${baseline.totals.warnings}${saved > 0 ? `, -${saved}` : ""})`
|
|
132
|
+
);
|
|
133
|
+
process.exit(0);
|
|
134
|
+
}
|
|
135
|
+
console.error("QA-A2.0: обнаружены новые предупреждения ESLint:");
|
|
136
|
+
for (const problem of problems) console.error(` - ${problem}`);
|
|
137
|
+
console.error("Если уменьшение осознанное — npm run lint:baseline:update");
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TP-6.2 — генератор счётчиков TEST-PLAN.md по маркерам.
|
|
3
|
+
*
|
|
4
|
+
* node scripts/gen-test-plan-counters.mjs # JSON в stdout
|
|
5
|
+
* node scripts/gen-test-plan-counters.mjs --write # обновить блок между маркерами
|
|
6
|
+
* node scripts/gen-test-plan-counters.mjs --out <file> # записать JSON в файл
|
|
7
|
+
*
|
|
8
|
+
* Маркеры в TEST-PLAN.md:
|
|
9
|
+
* <!-- counters:start -->
|
|
10
|
+
* <!-- counters:end -->
|
|
11
|
+
*
|
|
12
|
+
* Скрипт только считает фактические значения из кода/плана и не меняет остальной текст.
|
|
13
|
+
*/
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import url from "node:url";
|
|
17
|
+
|
|
18
|
+
const root = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), "..");
|
|
19
|
+
const planPath = path.join(root, "TEST-PLAN.md");
|
|
20
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
21
|
+
const plan = fs.readFileSync(planPath, "utf8");
|
|
22
|
+
|
|
23
|
+
const section = (title, next) => {
|
|
24
|
+
const from = plan.indexOf(title);
|
|
25
|
+
if (from < 0) return "";
|
|
26
|
+
const to = next ? plan.indexOf(next, from + title.length) : plan.length;
|
|
27
|
+
return plan.slice(from, to < 0 ? plan.length : to);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const appendixA = section("## Приложение A.", "## Приложение B.");
|
|
31
|
+
const appendixB = section("## Приложение B.", "## Приложение C.");
|
|
32
|
+
const appendixC = section("## Приложение C.", "---");
|
|
33
|
+
const coverage = section("## 5. Матрица покрытия автотестами", "## 6.");
|
|
34
|
+
|
|
35
|
+
const backtickNames = (text) =>
|
|
36
|
+
[...text.matchAll(/`([a-z][a-z0-9_-]+)`/g)].map((m) => m[1]);
|
|
37
|
+
const unique = (xs) => [...new Set(xs)];
|
|
38
|
+
|
|
39
|
+
const testFiles = fs
|
|
40
|
+
.readdirSync(root)
|
|
41
|
+
.filter((f) => /^test-.*\.mjs$/.test(f))
|
|
42
|
+
.sort();
|
|
43
|
+
const npmTestScripts = Object.keys(pkg.scripts ?? {}).filter((k) => k.startsWith("test"));
|
|
44
|
+
const rpcMethods = unique(backtickNames(appendixA)).filter((n) => /^[a-z][a-z0-9_]*$/.test(n));
|
|
45
|
+
const mcpTools = unique(backtickNames(appendixB)).filter((n) => /^[a-z][a-z0-9_]*$/.test(n));
|
|
46
|
+
const httpEndpoints = unique(
|
|
47
|
+
[...appendixC.matchAll(/`\s*(?:GET|POST)\s+([^`]+)`/g)].map((m) => m[1].trim()),
|
|
48
|
+
);
|
|
49
|
+
const coverageEntries = unique(
|
|
50
|
+
[...coverage.matchAll(/^\|\s*`([^`]+\.mjs)`/gm)].map((m) => m[1]),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const server = fs.readFileSync(path.join(root, "src", "server.ts"), "utf8");
|
|
54
|
+
const literalEndpoints = new Set(
|
|
55
|
+
[...server.matchAll(/pathname\s*===\s*"([^"]+)"/g)].map((m) => m[1]),
|
|
56
|
+
);
|
|
57
|
+
const paramEndpoints = new Set(
|
|
58
|
+
[...server.matchAll(/pathname\.startsWith\("([^"]+)"\)/g)].map((m) => m[1]),
|
|
59
|
+
);
|
|
60
|
+
const codeEndpoints = unique([...literalEndpoints, ...paramEndpoints]);
|
|
61
|
+
|
|
62
|
+
const counters = {
|
|
63
|
+
generatedAt: new Date().toISOString(),
|
|
64
|
+
pluginVersion: pkg.version,
|
|
65
|
+
schemaVersion:
|
|
66
|
+
Number(
|
|
67
|
+
/export const SCHEMA_VERSION = (\d+)/.exec(
|
|
68
|
+
fs.readFileSync(path.join(root, "src", "db", "schema.ts"), "utf8"),
|
|
69
|
+
)?.[1],
|
|
70
|
+
) ?? null,
|
|
71
|
+
testFiles: testFiles.length,
|
|
72
|
+
npmTestScripts: npmTestScripts.length,
|
|
73
|
+
mcpToolsPlan: mcpTools.length,
|
|
74
|
+
rpcMethodsPlan: rpcMethods.length,
|
|
75
|
+
httpEndpointsAppendix: httpEndpoints.length,
|
|
76
|
+
httpEndpointsCode: codeEndpoints.length,
|
|
77
|
+
coverageEntries: coverageEntries.length,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const json = JSON.stringify(counters, null, 2);
|
|
81
|
+
const args = process.argv.slice(2);
|
|
82
|
+
|
|
83
|
+
if (args.includes("--write")) {
|
|
84
|
+
const start = "<!-- counters:start -->";
|
|
85
|
+
const end = "<!-- counters:end -->";
|
|
86
|
+
if (!plan.includes(start) || !plan.includes(end)) {
|
|
87
|
+
console.error("В TEST-PLAN.md нет маркеров counters:start / counters:end");
|
|
88
|
+
process.exit(2);
|
|
89
|
+
}
|
|
90
|
+
const before = plan.slice(0, plan.indexOf(start) + start.length);
|
|
91
|
+
const after = plan.slice(plan.indexOf(end));
|
|
92
|
+
const table = [
|
|
93
|
+
"",
|
|
94
|
+
"| Счётчик | Значение | Источник |",
|
|
95
|
+
"|---|---|---|",
|
|
96
|
+
`| MCP-инструментов | ${counters.mcpToolsPlan} | Приложение B |`,
|
|
97
|
+
`| RPC-методов | ${counters.rpcMethodsPlan} | Приложение A |`,
|
|
98
|
+
`| HTTP-эндпоинтов | ${counters.httpEndpointsAppendix} | Приложение C |`,
|
|
99
|
+
`| Файлов test-*.mjs | ${counters.testFiles} | корень репозитория |`,
|
|
100
|
+
`| npm-скриптов test* | ${counters.npmTestScripts} | package.json |`,
|
|
101
|
+
`| Покрытие в §5 | ${counters.coverageEntries} | TEST-PLAN §5 |`,
|
|
102
|
+
`| SCHEMA_VERSION | ${counters.schemaVersion} | src/db/schema.ts |`,
|
|
103
|
+
"",
|
|
104
|
+
].join("\n");
|
|
105
|
+
fs.writeFileSync(planPath, before + table + after, "utf8");
|
|
106
|
+
console.log(`Счётчики обновлены в TEST-PLAN.md:\n${table}`);
|
|
107
|
+
} else {
|
|
108
|
+
const outIdx = args.indexOf("--out");
|
|
109
|
+
if (outIdx >= 0 && args[outIdx + 1]) {
|
|
110
|
+
const out = path.resolve(root, args[outIdx + 1]);
|
|
111
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
112
|
+
fs.writeFileSync(out, json + "\n", "utf8");
|
|
113
|
+
console.log(`Записано: ${out}`);
|
|
114
|
+
} else {
|
|
115
|
+
console.log(json);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# QA-3.8.2: resilient GitHub Actions fetch (ECONNRESET retry + timeout).
|
|
2
|
+
$ErrorActionPreference = 'Stop'
|
|
3
|
+
$out = Join-Path (Get-Location) 'github-ci-runs.json'
|
|
4
|
+
$headers = @{ 'User-Agent' = 'agent-steward-github-ci-check'; 'Accept' = 'application/vnd.github+json' }
|
|
5
|
+
$uri = 'https://api.github.com/repos/DeadSno/agent-steward/actions/runs?per_page=5'
|
|
6
|
+
$body = $null
|
|
7
|
+
for ($i = 1; $i -le 4; $i++) {
|
|
8
|
+
try {
|
|
9
|
+
$body = Invoke-RestMethod -Uri $uri -Headers $headers -TimeoutSec 30
|
|
10
|
+
break
|
|
11
|
+
} catch {
|
|
12
|
+
Write-Warning "GitHub fetch attempt ${i}: $($_.Exception.Message)"
|
|
13
|
+
if ($i -eq 4) { throw }
|
|
14
|
+
Start-Sleep -Seconds (2 * $i)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
$since = (Get-Date).ToUniversalTime().AddHours(-24)
|
|
18
|
+
$runs = @($body.workflow_runs | Where-Object { [datetime]::Parse($_.created_at).ToUniversalTime() -ge $since })
|
|
19
|
+
$jobs = @()
|
|
20
|
+
foreach ($run in $runs) {
|
|
21
|
+
$j = $null
|
|
22
|
+
for ($k = 1; $k -le 3; $k++) {
|
|
23
|
+
try {
|
|
24
|
+
$j = Invoke-RestMethod -Uri ("https://api.github.com/repos/DeadSno/agent-steward/actions/runs/$($run.id)/jobs") -Headers $headers -TimeoutSec 30
|
|
25
|
+
break
|
|
26
|
+
} catch {
|
|
27
|
+
Write-Warning "Jobs fetch attempt ${k}: $($_.Exception.Message)"
|
|
28
|
+
if ($k -eq 3) { $j = @{ jobs = @() }; break }
|
|
29
|
+
Start-Sleep -Seconds (2 * $k)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
foreach ($job in $j.jobs) {
|
|
33
|
+
$jobs += [pscustomobject]@{ runId = $run.id; name = $job.name; conclusion = $job.conclusion; url = $job.html_url; createdAt = $run.created_at }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
$jobs | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $out -Encoding UTF8
|
|
37
|
+
Write-Output "Fetched $($jobs.Count) jobs into $out"
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Post-flight commit+push for one QA-findings task (Деталь 1.5 / 1.6).
|
|
2
|
+
# Called by agent-steward's afterScript. Commits ONLY the files owned by the task
|
|
3
|
+
# and only when that task's quality gate wrote its own success marker.
|
|
4
|
+
# Generalizes scripts/qa-a2-commit.ps1: the marker is a parameter, so parallel
|
|
5
|
+
# tasks cannot consume each other's gate signal.
|
|
6
|
+
# PL-41: the commit itself is pathspec-limited — `git commit -m <msg> -- <files>`
|
|
7
|
+
# — so foreign staged changes never enter this task's commit. Plain
|
|
8
|
+
# `git add -- <files>` is NOT enough: `git add` stages only our files, but a bare
|
|
9
|
+
# `git commit -m <msg>` commits the WHOLE index, so anything another process
|
|
10
|
+
# staged in the meantime (or left staged before this run) would be swept into the
|
|
11
|
+
# commit. The `--` pathspec restricts the commit to the task's own file list
|
|
12
|
+
# regardless of what else sits in the index.
|
|
13
|
+
param(
|
|
14
|
+
[Parameter(Mandatory = $true)][string]$Message,
|
|
15
|
+
[Parameter(Mandatory = $true)][string]$Files,
|
|
16
|
+
[Parameter(Mandatory = $true)][string]$Marker
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
$ErrorActionPreference = 'Stop'
|
|
20
|
+
$root = Split-Path -Parent $PSScriptRoot
|
|
21
|
+
Set-Location -LiteralPath $root
|
|
22
|
+
$logFile = Join-Path $root 'pl-commit.log'
|
|
23
|
+
$markerPath = Join-Path $root $Marker
|
|
24
|
+
|
|
25
|
+
function Log([string]$text) {
|
|
26
|
+
Add-Content -LiteralPath $logFile -Value ("{0} {1}" -f (Get-Date -Format o), $text)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# git writes progress/errors to stderr; PowerShell 7 with ErrorActionPreference=Stop
|
|
30
|
+
# turns that into a terminating ErrorRecord even when push succeeds. Capture the
|
|
31
|
+
# real exit code instead (QA-A2/PL-7.1 lesson).
|
|
32
|
+
function Invoke-Git([string]$what, [string[]]$arguments) {
|
|
33
|
+
$old = $ErrorActionPreference
|
|
34
|
+
$ErrorActionPreference = 'Continue'
|
|
35
|
+
try {
|
|
36
|
+
$output = & git @arguments 2>&1
|
|
37
|
+
$code = $LASTEXITCODE
|
|
38
|
+
foreach ($line in $output) { Log ("[{0}] {1}" -f $what, [string]$line) }
|
|
39
|
+
return $code
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
$ErrorActionPreference = $old
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
$gateOk = Test-Path -LiteralPath $markerPath
|
|
48
|
+
if ($gateOk) {
|
|
49
|
+
Remove-Item -LiteralPath $markerPath -Force
|
|
50
|
+
}
|
|
51
|
+
if (-not $gateOk) {
|
|
52
|
+
Log "SKIP (quality gate did not pass): $Message"
|
|
53
|
+
exit 0
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$fileList = @($Files -split ';' | Where-Object { $_ } | ForEach-Object { $_.Trim() })
|
|
57
|
+
if ($fileList.Count -eq 0) {
|
|
58
|
+
Log "SKIP (no files): $Message"
|
|
59
|
+
exit 0
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if ((Invoke-Git 'add' (@('add', '--') + $fileList)) -ne 0) {
|
|
63
|
+
Log "FAIL add: $Message"
|
|
64
|
+
exit 1
|
|
65
|
+
}
|
|
66
|
+
$old = $ErrorActionPreference
|
|
67
|
+
$ErrorActionPreference = 'Continue'
|
|
68
|
+
try { $nothing = git diff --cached --quiet; $cleanCode = $LASTEXITCODE }
|
|
69
|
+
finally { $ErrorActionPreference = $old }
|
|
70
|
+
if ($cleanCode -eq 0) {
|
|
71
|
+
Log "SKIP (nothing to commit): $Message"
|
|
72
|
+
exit 0
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if ((Invoke-Git 'commit' (@('commit', '-m', $Message, '--') + $fileList)) -ne 0) {
|
|
76
|
+
Log "FAIL commit: $Message"
|
|
77
|
+
exit 1
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
$pushed = $false
|
|
81
|
+
for ($attempt = 1; $attempt -le 3; $attempt++) {
|
|
82
|
+
if ((Invoke-Git "push#$attempt" @('push', 'origin', 'dev')) -eq 0) {
|
|
83
|
+
$pushed = $true
|
|
84
|
+
break
|
|
85
|
+
}
|
|
86
|
+
Start-Sleep -Seconds 3
|
|
87
|
+
}
|
|
88
|
+
if (-not $pushed) {
|
|
89
|
+
# A parallel task may have pushed our commit already — verify before failing.
|
|
90
|
+
$null = Invoke-Git 'fetch' @('fetch', 'origin', 'dev')
|
|
91
|
+
$old = $ErrorActionPreference
|
|
92
|
+
$ErrorActionPreference = 'Continue'
|
|
93
|
+
try {
|
|
94
|
+
$local = (& git rev-parse HEAD 2>$null).Trim()
|
|
95
|
+
$remote = (& git rev-parse origin/dev 2>$null).Trim()
|
|
96
|
+
}
|
|
97
|
+
finally { $ErrorActionPreference = $old }
|
|
98
|
+
if ($local -and $local -eq $remote) {
|
|
99
|
+
$pushed = $true
|
|
100
|
+
Log "push: remote already contains HEAD (concurrent push)"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (-not $pushed) {
|
|
104
|
+
Log "FAIL push: $Message"
|
|
105
|
+
exit 1
|
|
106
|
+
}
|
|
107
|
+
Log "OK: $Message"
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
Log "ERROR: $($_.Exception.Message)"
|
|
111
|
+
exit 1
|
|
112
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# QA-A2 — post-flight commit+push for a single epic subtask.
|
|
2
|
+
# Called by agent-steward's afterScript. Commits ONLY the files owned by the task
|
|
3
|
+
# and only when the quality gate wrote its success marker (qa-a2-gate.passed).
|
|
4
|
+
param(
|
|
5
|
+
[Parameter(Mandatory = $true)][string]$Message,
|
|
6
|
+
[Parameter(Mandatory = $true)][string]$Files
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
$ErrorActionPreference = 'Stop'
|
|
10
|
+
$root = Split-Path -Parent $PSScriptRoot
|
|
11
|
+
Set-Location -LiteralPath $root
|
|
12
|
+
$logFile = Join-Path $root 'qa-a2-commit.log'
|
|
13
|
+
$marker = Join-Path $root 'qa-a2-gate.passed'
|
|
14
|
+
|
|
15
|
+
function Log([string]$text) {
|
|
16
|
+
Add-Content -LiteralPath $logFile -Value ("{0} {1}" -f (Get-Date -Format o), $text)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Native git writes progress/errors to stderr. With ErrorActionPreference=Stop
|
|
20
|
+
# PowerShell 7 turns that into a terminating ErrorRecord ("To https://...").
|
|
21
|
+
# Temporarily relax the preference and capture the real exit code instead.
|
|
22
|
+
function Invoke-Git([string]$what, [string[]]$arguments) {
|
|
23
|
+
$old = $ErrorActionPreference
|
|
24
|
+
$ErrorActionPreference = 'Continue'
|
|
25
|
+
try {
|
|
26
|
+
$output = & git @arguments 2>&1
|
|
27
|
+
$code = $LASTEXITCODE
|
|
28
|
+
foreach ($line in $output) { Log ("[{0}] {1}" -f $what, [string]$line) }
|
|
29
|
+
return $code
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
$ErrorActionPreference = $old
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
$gateOk = Test-Path -LiteralPath $marker
|
|
38
|
+
if ($gateOk) {
|
|
39
|
+
Remove-Item -LiteralPath $marker -Force
|
|
40
|
+
}
|
|
41
|
+
if (-not $gateOk) {
|
|
42
|
+
Log "SKIP (quality gate did not pass): $Message"
|
|
43
|
+
exit 0
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$fileList = @($Files -split ';' | Where-Object { $_ } | ForEach-Object { $_.Trim() })
|
|
47
|
+
if ($fileList.Count -eq 0) {
|
|
48
|
+
Log "SKIP (no files): $Message"
|
|
49
|
+
exit 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ((Invoke-Git 'add' (@('add', '--') + $fileList)) -ne 0) {
|
|
53
|
+
Log "FAIL add: $Message"
|
|
54
|
+
exit 1
|
|
55
|
+
}
|
|
56
|
+
$old = $ErrorActionPreference
|
|
57
|
+
$ErrorActionPreference = 'Continue'
|
|
58
|
+
try { $nothing = git diff --cached --quiet; $cleanCode = $LASTEXITCODE }
|
|
59
|
+
finally { $ErrorActionPreference = $old }
|
|
60
|
+
if ($cleanCode -eq 0) {
|
|
61
|
+
Log "SKIP (nothing to commit): $Message"
|
|
62
|
+
exit 0
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# PL-41: pathspec commit — only this task's files enter the commit; a bare
|
|
66
|
+
# `git commit -m` would commit the whole index including foreign staged changes.
|
|
67
|
+
if ((Invoke-Git 'commit' (@('commit', '-m', $Message, '--') + $fileList)) -ne 0) {
|
|
68
|
+
Log "FAIL commit: $Message"
|
|
69
|
+
exit 1
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
$pushed = $false
|
|
73
|
+
for ($attempt = 1; $attempt -le 3; $attempt++) {
|
|
74
|
+
if ((Invoke-Git "push#$attempt" @('push', 'origin', 'dev')) -eq 0) {
|
|
75
|
+
$pushed = $true
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
Start-Sleep -Seconds 3
|
|
79
|
+
}
|
|
80
|
+
if (-not $pushed) {
|
|
81
|
+
# A concurrent task may have pushed our commit already — verify before failing.
|
|
82
|
+
$null = Invoke-Git 'fetch' @('fetch', 'origin', 'dev')
|
|
83
|
+
$old = $ErrorActionPreference
|
|
84
|
+
$ErrorActionPreference = 'Continue'
|
|
85
|
+
try {
|
|
86
|
+
$local = (& git rev-parse HEAD 2>$null).Trim()
|
|
87
|
+
$remote = (& git rev-parse origin/dev 2>$null).Trim()
|
|
88
|
+
}
|
|
89
|
+
finally { $ErrorActionPreference = $old }
|
|
90
|
+
if ($local -and $local -eq $remote) {
|
|
91
|
+
$pushed = $true
|
|
92
|
+
Log "push: remote already contains HEAD (concurrent push)"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (-not $pushed) {
|
|
96
|
+
Log "FAIL push: $Message"
|
|
97
|
+
exit 1
|
|
98
|
+
}
|
|
99
|
+
Log "OK: $Message"
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
Log "ERROR: $($_.Exception.Message)"
|
|
103
|
+
exit 1
|
|
104
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Общий харнесс для временных домашних каталогов тестов.
|
|
3
|
+
*
|
|
4
|
+
* Каждая сюита получает свой собственный каталог (fs.mkdtemp), поэтому
|
|
5
|
+
* параллельный прогон не может пересечься с другой сюитой. Удаление делает
|
|
6
|
+
* несколько попыток с backoff: на Windows SQLite/WAL и дашборд могут держать
|
|
7
|
+
* файлы ещё несколько тиков после closeDb()/closeDashboardServer(), из-за чего
|
|
8
|
+
* обычный fs.rm падает с ENOTEMPTY.
|
|
9
|
+
*
|
|
10
|
+
* Если ОС так и не отпустила файл, тест НЕ падает из-за утечки temp-каталога —
|
|
11
|
+
* выводится предупреждение. Это сознательный компромисс: предсказуемость
|
|
12
|
+
* прогона важнее чистоты временной папки.
|
|
13
|
+
*/
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import fsp from "node:fs/promises";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
const DEFAULT_ATTEMPTS = 6;
|
|
20
|
+
|
|
21
|
+
// На Windows SQLite/дашборд могут держать файлы до выхода процесса. Вместо
|
|
22
|
+
// предупреждения в чистом прогоне откладываем последнюю попытку на `exit`,
|
|
23
|
+
// когда все дескрипторы уже закрыты (QA-P3.4).
|
|
24
|
+
const deferredCleanups = new Set();
|
|
25
|
+
function scheduleDeferredCleanup(target) {
|
|
26
|
+
if (deferredCleanups.has(target)) return;
|
|
27
|
+
deferredCleanups.add(target);
|
|
28
|
+
process.once("exit", () => {
|
|
29
|
+
try {
|
|
30
|
+
fs.rmSync(target, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
31
|
+
} catch {
|
|
32
|
+
// best effort: временный каталог не должен ломать выход процесса
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function sleepSync(ms) {
|
|
38
|
+
// Синхронная пауза без внешних зависимостей (для тестов с fs.rmSync).
|
|
39
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function makePaths(prefix) {
|
|
43
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
44
|
+
return {
|
|
45
|
+
root,
|
|
46
|
+
appData: path.join(root, "AppData"),
|
|
47
|
+
pluginDir: path.join(root, "AppData", "opencode", "windows-scheduler"),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Создаёт изолированный home синхронно (до динамических импортов сервера). */
|
|
52
|
+
export function createTestHomeSync(prefix) {
|
|
53
|
+
const paths = makePaths(prefix);
|
|
54
|
+
fs.mkdirSync(paths.pluginDir, { recursive: true });
|
|
55
|
+
return paths;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Асинхронный аналог createTestHomeSync. */
|
|
59
|
+
export async function createTestHome(prefix) {
|
|
60
|
+
const paths = makePaths(prefix);
|
|
61
|
+
await fsp.mkdir(paths.pluginDir, { recursive: true });
|
|
62
|
+
return paths;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Надёжная синхронная уборка с backoff. Возвращает true, если каталог удалён. */
|
|
66
|
+
export function removeTestHomeSync(target, { attempts = DEFAULT_ATTEMPTS, warn = true } = {}) {
|
|
67
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
68
|
+
try {
|
|
69
|
+
fs.rmSync(target, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
70
|
+
return true;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (err?.code === "ENOENT") return true;
|
|
73
|
+
if (attempt === attempts) {
|
|
74
|
+
if (process.platform === "win32") {
|
|
75
|
+
scheduleDeferredCleanup(target);
|
|
76
|
+
} else if (warn) {
|
|
77
|
+
console.warn(`Не удалось удалить временный каталог ${target}: ${String(err)}`);
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
sleepSync(100 * attempt);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Асинхронный аналог removeTestHomeSync. */
|
|
88
|
+
export async function removeTestHome(target, { attempts = DEFAULT_ATTEMPTS, warn = true } = {}) {
|
|
89
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
90
|
+
try {
|
|
91
|
+
await fsp.rm(target, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
92
|
+
return true;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (err?.code === "ENOENT") return true;
|
|
95
|
+
if (attempt === attempts) {
|
|
96
|
+
if (process.platform === "win32") {
|
|
97
|
+
scheduleDeferredCleanup(target);
|
|
98
|
+
} else if (warn) {
|
|
99
|
+
console.warn(`Не удалось удалить временный каталог ${target}: ${String(err)}`);
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
await new Promise((resolve) => setTimeout(resolve, 100 * attempt));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|