fix: 标明工作流扫描与分析证据完整性
保留不完整扫描中的既有告警指纹,并展示分页和分析证据不足。
This commit is contained in:
1 parent
c6d71843b7
commit
c813498da2
8 files changed
+84
-22
No files matched your search
@@ -78,6 +78,8 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
|
||||
## 调试与诊断结果契约
|
||||
|
||||
- 跨应用列表和节点搜索只读取各应用指定页;JSON 的 `pages` 与 `complete` 表示扫描范围,缺少总页数且结果满页时按不完整处理。健康检查在分页不完整或读取失败时保留既有告警指纹,避免误清;返回 `complete` 和 `scanErrors`。
|
||||
- `analyze` 返回 `evidenceComplete` 和 `evidenceErrors`,区分外部资料读取失败与已执行的静态检查;`--fail` 仍仅根据已发现的硬门禁设置退出码。静态检查通过不保证可安全发布。
|
||||
- 调试属于写操作:`--dry-run` 仅展示目标、发布选项和风险,不创建客户端或发起 Job;实际执行需要 `--yes` / `--confirm`。启用中的工作流仍可在确认后直接调试。
|
||||
- JSON 和预览均包含风险信息。执行结果提供 `productionEnabled`(状态未知时为 `null`)和 `warnings`。
|
||||
- `outcome` 为 `completed`、`failed`、`timed_out` 或 `incomplete`;只有完整成功才返回退出码 `0`。超时不取消已经发起的 Job,保留 `jobId` 以供 `workflow job` 续查。
|
||||
|
||||
@@ -75,15 +75,17 @@ export class WorkflowAlertStore {
|
||||
return { version: 1, alerts: {} };
|
||||
}
|
||||
|
||||
observe(alerts: WorkflowErrorAlert[]): WorkflowAlertCheckResult {
|
||||
observe(alerts: WorkflowErrorAlert[], options: { complete?: boolean } = {}): WorkflowAlertCheckResult {
|
||||
const data = this.read();
|
||||
const activeIds = new Set(alerts.map((alert) => alert.id));
|
||||
const newAlerts = alerts.filter(
|
||||
(alert) => data.alerts[alert.id]?.errorCount !== alert.errorCount
|
||||
);
|
||||
const updated = { ...data.alerts };
|
||||
for (const id of Object.keys(updated)) {
|
||||
if (!activeIds.has(id)) delete updated[id];
|
||||
if (options.complete !== false) {
|
||||
for (const id of Object.keys(updated)) {
|
||||
if (!activeIds.has(id)) delete updated[id];
|
||||
}
|
||||
}
|
||||
for (const alert of alerts) {
|
||||
updated[alert.id] = { errorCount: alert.errorCount, lastSeen: alert.observedAt };
|
||||
@@ -102,7 +104,7 @@ export class WorkflowAlertStore {
|
||||
`);
|
||||
|
||||
const tx = db.transaction((items: WorkflowErrorAlert[]) => {
|
||||
db.run("DELETE FROM workflow_error_alerts WHERE scope_key = ?", [this.scopeKey]);
|
||||
if (options.complete !== false) db.run("DELETE FROM workflow_error_alerts WHERE scope_key = ?", [this.scopeKey]);
|
||||
for (const alert of items) {
|
||||
upsert.run(
|
||||
this.scopeKey,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { expect, it, spyOn } from "bun:test";
|
||||
import * as applications from "../applications/services.js";
|
||||
import * as api from "./api.js";
|
||||
import { listAllWorkflows } from "./queries.js";
|
||||
|
||||
it("reports whether cross-application results cover all pages and applications", async () => {
|
||||
const platforms = spyOn(applications, "listBasicPlatforms").mockResolvedValue([{ id: "p", active: true }] as any);
|
||||
const list = spyOn(api, "listWorkflows").mockResolvedValue({ pipelineList: [], totalPages: 2, totalItems: 21 } as any);
|
||||
const clients = { corp: { credentials: { corpId: "corp" } }, ekbClient: {}, easoClient: {} } as any;
|
||||
const partial = await listAllWorkflows(clients, { page: 1, pageSize: 20 });
|
||||
expect(partial.complete).toBe(false);
|
||||
expect(partial.pages?.[0]?.totalPages).toBe(2);
|
||||
list.mockResolvedValue({ pipelineList: [], totalPages: 1, totalItems: 0 } as any);
|
||||
expect((await listAllWorkflows(clients)).complete).toBe(true);
|
||||
list.mockRejectedValue(new Error("unavailable"));
|
||||
const failed = await listAllWorkflows(clients);
|
||||
expect(failed.complete).toBe(false);
|
||||
expect(failed.errors).toHaveLength(1);
|
||||
platforms.mockRestore();
|
||||
list.mockRestore();
|
||||
});
|
||||
@@ -88,6 +88,8 @@ export interface ListAllWorkflowsOptions {
|
||||
export interface ListAllWorkflowsResult {
|
||||
workflows: WorkflowSummary[];
|
||||
errors: WorkflowListAllError[];
|
||||
pages?: Array<{ platformId: string; page: number; pageSize: number; totalPages: number; totalItems: number; complete: boolean }>;
|
||||
complete?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +106,7 @@ export async function listAllWorkflows(
|
||||
|
||||
const workflows: WorkflowSummary[] = [];
|
||||
const errors: WorkflowListAllError[] = [];
|
||||
const pages: NonNullable<ListAllWorkflowsResult["pages"]> = [];
|
||||
|
||||
await Promise.all(
|
||||
enabledPlatforms.map(async (platform) => {
|
||||
@@ -114,6 +117,13 @@ export async function listAllWorkflows(
|
||||
page,
|
||||
pageSize
|
||||
);
|
||||
// 服务端有时不提供分页总数;满页时无法证明没有下一页。
|
||||
const complete = page === 1 && (pageResult.totalPages > 0
|
||||
? pageResult.totalPages === 1
|
||||
: pageResult.totalItems > 0
|
||||
? pageResult.totalItems <= pageResult.pipelineList.length
|
||||
: pageResult.pipelineList.length < pageSize);
|
||||
pages.push({ platformId: platform.id, page, pageSize, totalPages: pageResult.totalPages, totalItems: pageResult.totalItems, complete });
|
||||
for (const workflow of pageResult.pipelineList) {
|
||||
workflows.push({
|
||||
...workflow,
|
||||
@@ -131,7 +141,7 @@ export async function listAllWorkflows(
|
||||
})
|
||||
);
|
||||
|
||||
return { workflows, errors };
|
||||
return { workflows, errors, pages, complete: errors.length === 0 && pages.every((item) => item.complete) };
|
||||
}
|
||||
|
||||
|
||||
@@ -164,6 +174,8 @@ export interface FindWorkflowsByTaskTypeOptions extends ListAllWorkflowsOptions
|
||||
export interface FindWorkflowsByTaskTypeResult {
|
||||
workflows: WorkflowWithMatches[];
|
||||
errors: WorkflowListAllError[];
|
||||
pages?: ListAllWorkflowsResult["pages"];
|
||||
complete?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -202,5 +214,5 @@ export async function findWorkflowsByTaskType(
|
||||
}
|
||||
}
|
||||
|
||||
return { workflows: matched, errors: [...all.errors, ...detailErrors] };
|
||||
return { workflows: matched, errors: [...all.errors, ...detailErrors], pages: all.pages, complete: all.complete === true && detailErrors.length === 0 };
|
||||
}
|
||||
@@ -172,6 +172,19 @@ describe("workflow draft state machine", () => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("preserves previously observed alerts when a scan is incomplete", () => {
|
||||
const dir = mkdtempSync("hose-workflow-alert-partial-");
|
||||
const file = join(dir, "alerts.json");
|
||||
const store = new WorkflowAlertStore(file);
|
||||
const alert = { id: "corp:platform:wf-1", pipelineId: "wf-1", platformId: "platform-1", pipelineName: "测试流程", errorCount: 1, state: 0, observedAt: 1 };
|
||||
expect(store.observe([alert]).newAlerts).toHaveLength(1);
|
||||
store.observe([], { complete: false });
|
||||
expect(store.observe([{ ...alert, observedAt: 2 }], { complete: false }).newAlerts).toHaveLength(0);
|
||||
store.observe([], { complete: true });
|
||||
expect(store.observe([alert]).newAlerts).toHaveLength(1);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("tracks dirty revisions and commits the server snapshot", () => {
|
||||
let state = createWorkflowDraft(workflow());
|
||||
state = patchWorkflowDraft(state, (current) => ({ ...current, label: "已修改" }), ["label"]);
|
||||
|
||||
Reference in new issue
Block a user