feat: add managed characterization and coverage closure
This commit is contained in:
@@ -5,16 +5,36 @@ import {
|
||||
traceApplicationFeatureEvidence,
|
||||
} from "./application/JavaScriptApplicationWorkflowService.js";
|
||||
import { runControlledReplay } from "./application/JavaScriptReplayService.js";
|
||||
import {
|
||||
executeNodeCharacterization,
|
||||
prepareNodeCharacterization,
|
||||
} from "./application/NodeRuntimeCharacterizationService.js";
|
||||
import {
|
||||
commitReconstructionCoverage,
|
||||
queryReconstructionCoverage,
|
||||
reconstructionCoverageCommitInputSchema,
|
||||
reconstructionCoverageQueryInputSchema,
|
||||
} from "./application/ReconstructionCoverageService.js";
|
||||
import {
|
||||
authorizeFileReadWithDeferredWrite,
|
||||
authorizeRootPermission,
|
||||
} from "./application/DeferredFileAuthorization.js";
|
||||
import { loadConfiguredPermissionAuthority } from "./application/PermissionConfiguration.js";
|
||||
import { CLI_COMMANDS } from "./cliCommandNames.js";
|
||||
import { parseCliJsonInput } from "./cliJsonInput.js";
|
||||
import { logCliCommand } from "./cliLogging.js";
|
||||
import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
projectAnalysisError,
|
||||
type AnalysisError,
|
||||
} from "./domain/errors.js";
|
||||
import type { JsonValue } from "./domain/jsonValue.js";
|
||||
import type { Logger } from "./logger.js";
|
||||
import { parseConfig } from "./config.js";
|
||||
import { LinuxJavaScriptReplayRunner } from "./replay/LinuxJavaScriptReplayRunner.js";
|
||||
import { SystemJavaScriptReplayHost } from "./replay/SystemJavaScriptReplayHost.js";
|
||||
import type { AppConfig } from "./config.js";
|
||||
import type { PermissionAuthority } from "./application/PermissionAuthority.js";
|
||||
|
||||
/** Register CLI equivalents of provider-neutral application graph workflows. */
|
||||
export const registerApplicationCommands = (
|
||||
@@ -64,8 +84,158 @@ export const registerApplicationCommands = (
|
||||
return result.ok ? result.value : projectAnalysisError(result.error);
|
||||
}),
|
||||
});
|
||||
registerAuthorizedJsonCommand(
|
||||
cli,
|
||||
logger,
|
||||
CLI_COMMANDS.prepareNodeCharacterization,
|
||||
"Prepare one exact Node/JavaScript characterization without execution",
|
||||
(config, authority, input) =>
|
||||
prepareNodeCharacterization(replayDependencies(config, authority), input),
|
||||
);
|
||||
registerAuthorizedJsonCommand(
|
||||
cli,
|
||||
logger,
|
||||
CLI_COMMANDS.executeNodeCharacterization,
|
||||
"Execute one separately approved exact Node/JavaScript characterization",
|
||||
(config, authority, input) =>
|
||||
executeNodeCharacterization(replayDependencies(config, authority), input),
|
||||
);
|
||||
registerCoverageCommands(cli, logger);
|
||||
};
|
||||
|
||||
const registerAuthorizedJsonCommand = (
|
||||
cli: ReturnType<typeof Cli.create>,
|
||||
logger: Logger,
|
||||
name: string,
|
||||
description: string,
|
||||
workflow: (
|
||||
config: AppConfig,
|
||||
authority: PermissionAuthority,
|
||||
input: unknown,
|
||||
) => Promise<
|
||||
| { readonly ok: true; readonly value: JsonValue }
|
||||
| { readonly ok: false; readonly error: AnalysisError }
|
||||
>,
|
||||
): void => {
|
||||
cli.command(name, {
|
||||
description,
|
||||
args: z.object({
|
||||
inputJson: z.string().describe("Inline workflow JSON or JSON file path"),
|
||||
}),
|
||||
run: ({ args }) =>
|
||||
logCliCommand(logger, name, async () => {
|
||||
const input = await parseCliJsonInput(args.inputJson, name);
|
||||
if (!input.ok) return input.error;
|
||||
const configured = await configuredAuthority();
|
||||
if (!configured.ok) return configured.error;
|
||||
const result = await workflow(
|
||||
configured.config,
|
||||
configured.authority,
|
||||
input.value,
|
||||
);
|
||||
return result.ok ? result.value : projectAnalysisError(result.error);
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const registerCoverageCommands = (
|
||||
cli: ReturnType<typeof Cli.create>,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
registerAuthorizedJsonCommand(
|
||||
cli,
|
||||
logger,
|
||||
CLI_COMMANDS.commitReconstructionCoverage,
|
||||
"Commit one canonical reconstruction coverage workspace revision",
|
||||
async (config, authority, input) => {
|
||||
const parsed = reconstructionCoverageCommitInputSchema.safeParse(input);
|
||||
if (!parsed.success)
|
||||
return {
|
||||
ok: false,
|
||||
error: new AnalysisInputError(
|
||||
CLI_COMMANDS.commitReconstructionCoverage,
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
};
|
||||
const authorization = await authorizeFileReadWithDeferredWrite(
|
||||
authority,
|
||||
{
|
||||
path: parsed.data.workspace_path,
|
||||
readCapability: "investigation_workspace_read",
|
||||
writeCapability: "investigation_workspace_write",
|
||||
operation: CLI_COMMANDS.commitReconstructionCoverage,
|
||||
},
|
||||
);
|
||||
if (!authorization.ok) return authorization;
|
||||
const write = await authorization.value.authorizeWrite();
|
||||
if (!write.ok) return write;
|
||||
return commitReconstructionCoverage(
|
||||
parsed.data,
|
||||
config.evidenceFilePolicy,
|
||||
);
|
||||
},
|
||||
);
|
||||
registerAuthorizedJsonCommand(
|
||||
cli,
|
||||
logger,
|
||||
CLI_COMMANDS.queryReconstructionCoverage,
|
||||
"Evaluate one fail-closed reconstruction coverage boundary",
|
||||
async (config, authority, input) => {
|
||||
const parsed = reconstructionCoverageQueryInputSchema.safeParse(input);
|
||||
if (!parsed.success)
|
||||
return {
|
||||
ok: false,
|
||||
error: new AnalysisInputError(
|
||||
CLI_COMMANDS.queryReconstructionCoverage,
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
};
|
||||
const authorized = await authorizeRootPermission(authority, {
|
||||
capability: "investigation_workspace_read",
|
||||
roots: [parsed.data.workspace_path],
|
||||
access: "read",
|
||||
operation: CLI_COMMANDS.queryReconstructionCoverage,
|
||||
});
|
||||
if (!authorized.ok) return authorized;
|
||||
return queryReconstructionCoverage(
|
||||
parsed.data,
|
||||
config.evidenceFilePolicy,
|
||||
Date.now(),
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const configuredAuthority = async (): Promise<
|
||||
| {
|
||||
readonly ok: true;
|
||||
readonly config: AppConfig;
|
||||
readonly authority: PermissionAuthority;
|
||||
}
|
||||
| {
|
||||
readonly ok: false;
|
||||
readonly error: ReturnType<typeof projectAnalysisError>;
|
||||
}
|
||||
> => {
|
||||
const config = parseConfig(process.env);
|
||||
if (!config.ok)
|
||||
return { ok: false, error: projectAnalysisError(config.error) };
|
||||
const authority = await loadConfiguredPermissionAuthority(config.value);
|
||||
return authority.ok
|
||||
? { ok: true, config: config.value, authority: authority.value }
|
||||
: { ok: false, error: projectAnalysisError(authority.error) };
|
||||
};
|
||||
|
||||
const replayDependencies = (
|
||||
config: AppConfig,
|
||||
authority: PermissionAuthority,
|
||||
) => ({
|
||||
policy: config.javascriptReplayPolicy,
|
||||
host: new SystemJavaScriptReplayHost(),
|
||||
runner: new LinuxJavaScriptReplayRunner(),
|
||||
authority,
|
||||
});
|
||||
|
||||
const registerJsonCommand = (
|
||||
cli: ReturnType<typeof Cli.create>,
|
||||
logger: Logger,
|
||||
|
||||
Reference in New Issue
Block a user