fix: 收口依赖兼容与会话撤销
为 miniprogram-ci 和 Jimp 依赖增加兼容 patch 与 smoke test;修复平台模板管理员路由漏配;收紧模板契约校验;为 admin/customer 增加 token 撤销和集中会话存储;同步品牌切换角色、doctor source hash、多屏宽截图证据和 CI 构建门禁。
This commit is contained in:
1 parent
4f0b50c7f1
commit
3017e3eb49
65 files changed
+1623
-975
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import crypto from "node:crypto";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import ts from "typescript";
|
||||
@@ -413,6 +414,53 @@ export function applyManualReview(reports, reviews, reviewScope) {
|
||||
return reports;
|
||||
}
|
||||
|
||||
function walkRepositoryFiles(root, directory = root) {
|
||||
const files = [];
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
if (
|
||||
entry.name === ".git" ||
|
||||
entry.name === "node_modules" ||
|
||||
entry.name === "dist" ||
|
||||
entry.name === ".turbo"
|
||||
)
|
||||
continue;
|
||||
const full = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) files.push(...walkRepositoryFiles(root, full));
|
||||
else if (entry.isFile()) files.push(full);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
export function sourceTreeHash(root) {
|
||||
const rootPath = path.resolve(root);
|
||||
let files;
|
||||
if (fs.existsSync(path.join(rootPath, ".git"))) {
|
||||
const output = execFileSync(
|
||||
"git",
|
||||
["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
||||
{ cwd: rootPath, maxBuffer: 64 * 1024 * 1024 },
|
||||
);
|
||||
files = output
|
||||
.toString("utf8")
|
||||
.split("\0")
|
||||
.filter((file) => file && !file.startsWith(".codex-tasks/"))
|
||||
.map((file) => path.join(rootPath, file));
|
||||
} else {
|
||||
files = walkRepositoryFiles(rootPath).filter(
|
||||
(file) => !path.relative(rootPath, file).startsWith(".codex-tasks/"),
|
||||
);
|
||||
}
|
||||
files.sort();
|
||||
const hash = crypto.createHash("sha256");
|
||||
for (const file of files) {
|
||||
hash.update(path.relative(rootPath, file));
|
||||
hash.update("\0");
|
||||
hash.update(fs.readFileSync(file));
|
||||
hash.update("\0");
|
||||
}
|
||||
return hash.digest("hex");
|
||||
}
|
||||
|
||||
export function applyCompletionEvidence(reports, registry, root) {
|
||||
if (registry === undefined) {
|
||||
for (const report of reports) report.completionStatus = "unverified";
|
||||
@@ -424,7 +472,8 @@ export function applyCompletionEvidence(reports, registry, root) {
|
||||
registry.scope !== "模板完成证据登记,保留命令、日志与产物哈希" ||
|
||||
!registry.templates ||
|
||||
typeof registry.templates !== "object" ||
|
||||
Array.isArray(registry.templates)
|
||||
Array.isArray(registry.templates) ||
|
||||
!/^[a-f0-9]{64}$/.test(registry.sourceTreeHash ?? "")
|
||||
) {
|
||||
throw new Error("Completion evidence registry has an unsupported schema");
|
||||
}
|
||||
@@ -439,16 +488,23 @@ export function applyCompletionEvidence(reports, registry, root) {
|
||||
};
|
||||
const validEvidence = (evidence) => {
|
||||
if (!evidence || evidence.status !== "passed" || !Array.isArray(evidence.commands)) return null;
|
||||
if (!evidence.commands.length || evidence.commands.some((command) => !command.trim()))
|
||||
if (
|
||||
!evidence.commands.length ||
|
||||
evidence.commands.some((command) => !command.trim() || /<[^>]+>/.test(command))
|
||||
)
|
||||
return null;
|
||||
if (evidence.exitCode !== 0) return null;
|
||||
if (!Array.isArray(evidence.artifacts) || !evidence.artifacts.length) return null;
|
||||
return evidence;
|
||||
};
|
||||
|
||||
const currentSourceTreeHash = sourceTreeHash(root);
|
||||
let complete = true;
|
||||
for (const report of reports) {
|
||||
const evidence = registry.templates[report.template] ?? {};
|
||||
const completionIssues = [];
|
||||
if (registry.sourceTreeHash !== currentSourceTreeHash)
|
||||
completionIssues.push("source tree hash mismatch");
|
||||
for (const key of report.requiredEvidence) {
|
||||
const item = validEvidence(evidence[key]);
|
||||
if (!item) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
applyCompletionEvidence,
|
||||
applyManualReview,
|
||||
diagnoseTemplate,
|
||||
sourceTreeHash,
|
||||
} from "../lib/template-doctor.mjs";
|
||||
|
||||
test("真实模板自动发现并读取完整声明,生成可追溯区域报告", () => {
|
||||
@@ -91,6 +92,7 @@ test("完成证据登记必须覆盖全部要求并校验产物哈希", () => {
|
||||
const evidence = (items) => ({
|
||||
schemaVersion: 1,
|
||||
scope: "模板完成证据登记,保留命令、日志与产物哈希",
|
||||
sourceTreeHash: sourceTreeHash(root),
|
||||
templates: {
|
||||
fixture: Object.fromEntries(
|
||||
report.requiredEvidence.map((key) => [
|
||||
@@ -98,6 +100,7 @@ test("完成证据登记必须覆盖全部要求并校验产物哈希", () => {
|
||||
items.includes(key)
|
||||
? {
|
||||
status: "passed",
|
||||
exitCode: 0,
|
||||
commands: ["pnpm test"],
|
||||
artifacts: [{ path: "integration.log", sha256 }],
|
||||
}
|
||||
@@ -129,6 +132,26 @@ test("完成证据登记必须覆盖全部要求并校验产物哈希", () => {
|
||||
const checksumMismatch = applyCompletionEvidence([structuredClone(report)], invalid, root);
|
||||
assert.equal(checksumMismatch.completionStatus, "incomplete");
|
||||
assert.match(checksumMismatch.reports[0].completionIssues.join("\n"), /checksum mismatch/);
|
||||
|
||||
const staleSource = evidence(report.requiredEvidence);
|
||||
staleSource.sourceTreeHash = "0".repeat(64);
|
||||
const sourceMismatch = applyCompletionEvidence([structuredClone(report)], staleSource, root);
|
||||
assert.equal(sourceMismatch.completionStatus, "incomplete");
|
||||
assert.match(sourceMismatch.reports[0].completionIssues.join("\n"), /source tree hash/);
|
||||
|
||||
const failedCommand = evidence(report.requiredEvidence);
|
||||
failedCommand.templates.fixture["visual-reference"].exitCode = 1;
|
||||
const failed = applyCompletionEvidence([structuredClone(report)], failedCommand, root);
|
||||
assert.equal(failed.completionStatus, "incomplete");
|
||||
|
||||
const placeholderCommand = evidence(report.requiredEvidence);
|
||||
placeholderCommand.templates.fixture["visual-reference"].commands = ["pnpm test --out <dir>"];
|
||||
const placeholder = applyCompletionEvidence(
|
||||
[structuredClone(report)],
|
||||
placeholderCommand,
|
||||
root,
|
||||
);
|
||||
assert.equal(placeholder.completionStatus, "incomplete");
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user