auditor-lambda 0.11.0 → 0.11.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/dist/cli/auditStep.js +15 -1
- package/dist/cli/dispatch.js +3 -0
- package/dist/extractors/disposition.js +15 -1
- package/dist/extractors/pathPatterns.d.ts +13 -0
- package/dist/extractors/pathPatterns.js +28 -1
- package/dist/orchestrator/resultIngestion.d.ts +14 -0
- package/dist/orchestrator/resultIngestion.js +28 -0
- package/dist/prompts/renderWorkerPrompt.js +3 -0
- package/dist/validation/auditResults.js +7 -3
- package/package.json +1 -1
package/dist/cli/auditStep.js
CHANGED
|
@@ -6,6 +6,7 @@ import { advanceAudit } from "../orchestrator/advance.js";
|
|
|
6
6
|
import { deriveAuditState } from "../orchestrator/state.js";
|
|
7
7
|
import { decideNextStep } from "../orchestrator/nextStep.js";
|
|
8
8
|
import { sizeIndexFromManifest } from "../orchestrator/reviewPackets.js";
|
|
9
|
+
import { partitionOrphanedAuditResults } from "../orchestrator/resultIngestion.js";
|
|
9
10
|
import { validateAuditResults, formatAuditResultIssues, } from "../validation/auditResults.js";
|
|
10
11
|
import { formatAuditResultValidationError } from "./workerResult.js";
|
|
11
12
|
import { looksLikeCliFlag, listBatchResultFiles } from "./args.js";
|
|
@@ -38,10 +39,23 @@ export async function runAuditStep(options) {
|
|
|
38
39
|
if (looksLikeCliFlag(options.auditResultsPath)) {
|
|
39
40
|
throw new Error(`Invalid audit results path '${options.auditResultsPath}'. This looks like a CLI flag rather than a file path.`);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
let auditResults = options.auditResultsPath
|
|
42
43
|
? await readJsonFile(options.auditResultsPath)
|
|
43
44
|
: undefined;
|
|
44
45
|
if (auditResults !== undefined) {
|
|
46
|
+
// Drop results whose task_id is no longer in the active manifest — e.g.
|
|
47
|
+
// selective-deepening tasks pruned by a later re-plan, whose orphaned answers
|
|
48
|
+
// would otherwise abort the whole batch at the validation gate below and
|
|
49
|
+
// strand every valid result. They cannot be ingested (coverage is keyed by
|
|
50
|
+
// the active task set), so skip-and-warn instead of throwing; results for
|
|
51
|
+
// KNOWN tasks with real errors still abort. The filtered array is what flows
|
|
52
|
+
// to advanceAudit, so orphans are neither validated nor ingested.
|
|
53
|
+
const partition = partitionOrphanedAuditResults(auditResults, new Set((bundle.audit_tasks ?? []).map((task) => task.task_id)));
|
|
54
|
+
if (partition && partition.orphanedTaskIds.length > 0) {
|
|
55
|
+
process.stderr.write(`audit-results ingestion: skipped ${partition.orphanedTaskIds.length} result(s) whose task_id ` +
|
|
56
|
+
`is not in the active manifest (orphaned by re-planning): ${partition.orphanedTaskIds.join(", ")}\n`);
|
|
57
|
+
auditResults = partition.retained;
|
|
58
|
+
}
|
|
45
59
|
const issues = validateAuditResults(auditResults, bundle.audit_tasks ?? [], {
|
|
46
60
|
lineIndex,
|
|
47
61
|
});
|
package/dist/cli/dispatch.js
CHANGED
|
@@ -335,6 +335,9 @@ export function buildPacketPrompt(params) {
|
|
|
335
335
|
"Produce one JSON array containing exactly one AuditResult object for each listed task.",
|
|
336
336
|
"Windows PowerShell: do not pipe an inline foreach statement directly into ConvertTo-Json.",
|
|
337
337
|
"Assign the foreach output to a variable first, then pipe that variable to ConvertTo-Json.",
|
|
338
|
+
"PowerShell also unwraps single-element arrays: @(@{...}) collapses to one object, so a",
|
|
339
|
+
"one-result submission serializes as an object (not a 1-element array) and is rejected. Wrap it",
|
|
340
|
+
"yourself: '[' + (ConvertTo-Json $obj -Depth 12) + ']', or build the array with Write-Output -NoEnumerate.",
|
|
338
341
|
"",
|
|
339
342
|
"Schema file (resolve relative to this prompt's directory): audit_result.schema.json",
|
|
340
343
|
" $refs resolved from the same directory: finding.schema.json, audit_task.schema.json",
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { isNodeModulesOrGit, isTmpPath, isBuildOutput, isVendorPath, isBinaryArtifact, isLicensePath, isLockfilePath, isLogPath, isDocPath, isGeneratedPath, isAuditArtifactPath, isGeneratedTestArtifactPath, isGeneratedInstallArtifactPath, isExamplesOrFixturesPath, normalizeExtractorPath, } from "./pathPatterns.js";
|
|
1
|
+
import { isNodeModulesOrGit, isPackageManagerCachePath, isTmpPath, isBuildOutput, isVendorPath, isBinaryArtifact, isLicensePath, isLockfilePath, isLogPath, isDocPath, isGeneratedPath, isAuditArtifactPath, isAuditToolOutputArtifact, isGeneratedTestArtifactPath, isGeneratedInstallArtifactPath, isExamplesOrFixturesPath, normalizeExtractorPath, } from "./pathPatterns.js";
|
|
2
2
|
function inferDisposition(path) {
|
|
3
3
|
const normalized = normalizeExtractorPath(path);
|
|
4
4
|
if (isNodeModulesOrGit(normalized)) {
|
|
5
5
|
return { path, status: "excluded", reason: "node_modules or .git excluded by convention." };
|
|
6
6
|
}
|
|
7
|
+
if (isPackageManagerCachePath(normalized)) {
|
|
8
|
+
return {
|
|
9
|
+
path,
|
|
10
|
+
status: "excluded",
|
|
11
|
+
reason: "Package-manager cache (npm _cacache/npm-cache) excluded by convention.",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
7
14
|
if (isTmpPath(normalized)) {
|
|
8
15
|
return {
|
|
9
16
|
path,
|
|
@@ -40,6 +47,13 @@ function inferDisposition(path) {
|
|
|
40
47
|
reason: "Generated audit artifact.",
|
|
41
48
|
};
|
|
42
49
|
}
|
|
50
|
+
if (isAuditToolOutputArtifact(normalized)) {
|
|
51
|
+
return {
|
|
52
|
+
path,
|
|
53
|
+
status: "generated",
|
|
54
|
+
reason: "audit-tools pipeline output (findings/report) — a data deliverable, not source.",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
43
57
|
if (isGeneratedPath(normalized)) {
|
|
44
58
|
return {
|
|
45
59
|
path,
|
|
@@ -24,6 +24,19 @@ export declare function isDocPath(normalized: string): boolean;
|
|
|
24
24
|
export declare function isGeneratedInstallArtifactPath(normalized: string): boolean;
|
|
25
25
|
export declare function isGeneratedTestArtifactPath(normalized: string): boolean;
|
|
26
26
|
export declare function isAuditArtifactPath(normalized: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Package-manager cache stores — npm's content-addressed `_cacache`, a nested
|
|
29
|
+
* `npm-cache`, or a local `.npm` — are dependency blobs, never the audited
|
|
30
|
+
* project's source. Smoke-test temp dirs can leave these inside the repo tree.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isPackageManagerCachePath(normalized: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The pipeline's own canonical machine contracts. When audit-tools audits itself
|
|
35
|
+
* (or any repo that checked one in) these are data deliverables, not source —
|
|
36
|
+
* auditing them yields only "this is JSON data" noise. The matching `*-report.md`
|
|
37
|
+
* renders are already handled as `doc_only` by `isDocPath`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isAuditToolOutputArtifact(normalized: string): boolean;
|
|
27
40
|
export declare function isTestPath(normalized: string): boolean;
|
|
28
41
|
export declare function isInterfacePath(normalized: string): boolean;
|
|
29
42
|
export declare function isDataLayerPath(normalized: string): boolean;
|
|
@@ -22,6 +22,9 @@ const BINARY_EXTENSIONS = [
|
|
|
22
22
|
".otf",
|
|
23
23
|
".pdf",
|
|
24
24
|
".zip",
|
|
25
|
+
".tgz",
|
|
26
|
+
".tar",
|
|
27
|
+
".gz",
|
|
25
28
|
];
|
|
26
29
|
const LOCKFILE_NAMES = [
|
|
27
30
|
"package-lock.json",
|
|
@@ -204,7 +207,31 @@ export function isGeneratedTestArtifactPath(normalized) {
|
|
|
204
207
|
return splitSegments(normalized).some((segment) => segment.startsWith(".test-") && segment.endsWith("-artifacts"));
|
|
205
208
|
}
|
|
206
209
|
export function isAuditArtifactPath(normalized) {
|
|
207
|
-
return hasSegment(normalized, ".audit-tools")
|
|
210
|
+
return (hasSegment(normalized, ".audit-tools") ||
|
|
211
|
+
hasSegment(normalized, ".audit-artifacts"));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Package-manager cache stores — npm's content-addressed `_cacache`, a nested
|
|
215
|
+
* `npm-cache`, or a local `.npm` — are dependency blobs, never the audited
|
|
216
|
+
* project's source. Smoke-test temp dirs can leave these inside the repo tree.
|
|
217
|
+
*/
|
|
218
|
+
export function isPackageManagerCachePath(normalized) {
|
|
219
|
+
return (hasSegment(normalized, "_cacache") ||
|
|
220
|
+
hasSegment(normalized, "npm-cache") ||
|
|
221
|
+
hasSegment(normalized, ".npm"));
|
|
222
|
+
}
|
|
223
|
+
const AUDIT_TOOL_OUTPUT_BASENAMES = new Set([
|
|
224
|
+
"audit-findings.json",
|
|
225
|
+
"remediation-outcomes.json",
|
|
226
|
+
]);
|
|
227
|
+
/**
|
|
228
|
+
* The pipeline's own canonical machine contracts. When audit-tools audits itself
|
|
229
|
+
* (or any repo that checked one in) these are data deliverables, not source —
|
|
230
|
+
* auditing them yields only "this is JSON data" noise. The matching `*-report.md`
|
|
231
|
+
* renders are already handled as `doc_only` by `isDocPath`.
|
|
232
|
+
*/
|
|
233
|
+
export function isAuditToolOutputArtifact(normalized) {
|
|
234
|
+
return AUDIT_TOOL_OUTPUT_BASENAMES.has(baseName(normalized));
|
|
208
235
|
}
|
|
209
236
|
export function isTestPath(normalized) {
|
|
210
237
|
const segments = splitSegments(normalized);
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import type { AuditResult, AuditTask, CoverageMatrix } from "../types.js";
|
|
2
2
|
export declare function ingestAuditResults(coverageMatrix: CoverageMatrix, results: AuditResult[]): CoverageMatrix;
|
|
3
3
|
export declare function updateAuditTaskStatuses(tasks: AuditTask[] | undefined, results: AuditResult[]): AuditTask[] | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Splits raw (unvalidated) audit results into those whose `task_id` is still in
|
|
6
|
+
* the active task manifest and those orphaned by a later re-plan (e.g. selective-
|
|
7
|
+
* deepening tasks pruned in a subsequent round). Orphaned results cannot be
|
|
8
|
+
* ingested — coverage is keyed by the active task set — and must not abort an
|
|
9
|
+
* otherwise-valid batch at the ingestion validation gate. Returns the retained
|
|
10
|
+
* results plus the orphaned task ids so the caller can skip-and-warn, or `null`
|
|
11
|
+
* when there is nothing to filter (not an array, or no active manifest yet),
|
|
12
|
+
* signaling the caller to pass the results through unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function partitionOrphanedAuditResults(results: unknown, activeTaskIds: Set<string>): {
|
|
15
|
+
retained: unknown[];
|
|
16
|
+
orphanedTaskIds: string[];
|
|
17
|
+
} | null;
|
|
@@ -32,3 +32,31 @@ export function updateAuditTaskStatuses(tasks, results) {
|
|
|
32
32
|
};
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Splits raw (unvalidated) audit results into those whose `task_id` is still in
|
|
37
|
+
* the active task manifest and those orphaned by a later re-plan (e.g. selective-
|
|
38
|
+
* deepening tasks pruned in a subsequent round). Orphaned results cannot be
|
|
39
|
+
* ingested — coverage is keyed by the active task set — and must not abort an
|
|
40
|
+
* otherwise-valid batch at the ingestion validation gate. Returns the retained
|
|
41
|
+
* results plus the orphaned task ids so the caller can skip-and-warn, or `null`
|
|
42
|
+
* when there is nothing to filter (not an array, or no active manifest yet),
|
|
43
|
+
* signaling the caller to pass the results through unchanged.
|
|
44
|
+
*/
|
|
45
|
+
export function partitionOrphanedAuditResults(results, activeTaskIds) {
|
|
46
|
+
if (!Array.isArray(results) || activeTaskIds.size === 0) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const orphanedTaskIds = [];
|
|
50
|
+
const retained = results.filter((entry) => {
|
|
51
|
+
const taskId = entry && typeof entry === "object" && !Array.isArray(entry) &&
|
|
52
|
+
typeof entry.task_id === "string"
|
|
53
|
+
? entry.task_id
|
|
54
|
+
: undefined;
|
|
55
|
+
if (taskId !== undefined && !activeTaskIds.has(taskId)) {
|
|
56
|
+
orphanedTaskIds.push(taskId);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
return { retained, orphanedTaskIds };
|
|
62
|
+
}
|
|
@@ -44,6 +44,9 @@ export function renderWorkerPrompt(task) {
|
|
|
44
44
|
"Constraint: line_end must not exceed total_lines for that file.",
|
|
45
45
|
"Windows PowerShell: do not pipe an inline foreach statement directly into ConvertTo-Json.",
|
|
46
46
|
"Assign the foreach output to a variable first, then pipe that variable to ConvertTo-Json.",
|
|
47
|
+
"PowerShell also unwraps single-element arrays: @(@{...}) collapses to one object, so a one-result",
|
|
48
|
+
"submission serializes as an object (not a 1-element array) and is rejected. Wrap it yourself:",
|
|
49
|
+
"'[' + (ConvertTo-Json $obj -Depth 12) + ']', or build the array with Write-Output -NoEnumerate.",
|
|
47
50
|
`Write only the JSON array of AuditResult objects to: ${task.audit_results_path}`,
|
|
48
51
|
];
|
|
49
52
|
if (usesDeferredWorkerCommand(task)) {
|
|
@@ -305,7 +305,8 @@ function validateVerificationFollowupTask(task, label, taskId, resultIndex, expe
|
|
|
305
305
|
result_index: resultIndex,
|
|
306
306
|
task_id: taskId,
|
|
307
307
|
field: `${label}.file_paths[${index}]`,
|
|
308
|
-
message: `${label}.file_paths[${index}] references '${path}', which is outside the verification task's file_coverage
|
|
308
|
+
message: `${label}.file_paths[${index}] references '${path}', which is outside the verification task's file_coverage. ` +
|
|
309
|
+
`Followup tasks list files in 'file_paths' (array of strings), not 'file_coverage'; allowed: ${[...allowedPaths].join(", ")}.`,
|
|
309
310
|
});
|
|
310
311
|
}
|
|
311
312
|
}
|
|
@@ -481,7 +482,8 @@ export function validateAuditResults(results, tasks, options = {}) {
|
|
|
481
482
|
result_index: i,
|
|
482
483
|
task_id: taskId,
|
|
483
484
|
field: `file_coverage[${j}].path`,
|
|
484
|
-
message: `file_coverage path '${entry.path}' is not listed in the task file_paths
|
|
485
|
+
message: `file_coverage path '${entry.path}' is not listed in the task file_paths. ` +
|
|
486
|
+
`Declare only assigned files; allowed for this task: ${task.file_paths.join(", ")}.`,
|
|
485
487
|
});
|
|
486
488
|
}
|
|
487
489
|
else if (seenCoveragePaths.has(entryNorm)) {
|
|
@@ -595,7 +597,9 @@ export function validateAuditResults(results, tasks, options = {}) {
|
|
|
595
597
|
result_index: i,
|
|
596
598
|
task_id: taskId,
|
|
597
599
|
field: `${label}.affected_files[${k}].path`,
|
|
598
|
-
message: `affected_files path '${affected.path}' is not in the declared assigned file_coverage
|
|
600
|
+
message: `affected_files path '${affected.path}' is not in the declared assigned file_coverage. ` +
|
|
601
|
+
`Add it to this result's file_coverage first` +
|
|
602
|
+
(task ? `; the task's assigned files are: ${task.file_paths.join(", ")}.` : "."),
|
|
599
603
|
});
|
|
600
604
|
continue;
|
|
601
605
|
}
|