import assert from "node:assert/strict"; import { openAgentRunStoreFromEnv } from "../../mgr/store.js"; import { postgresMigrationContract } from "../../mgr/postgres-store.js"; import { redactText } from "../../common/redaction.js"; import { AgentRunError } from "../../common/errors.js"; import type { SelfTestCase } from "../harness.js"; const selfTest: SelfTestCase = async () => { assert.equal(redactText("Authorization: Bearer abc123"), "Authorization: Bearer REDACTED"); assert.equal(redactText('{"token":"test-token-material"}').includes("test-token-material"), false); await assert.rejects( () => openAgentRunStoreFromEnv({}), (error) => error instanceof AgentRunError && error.failureKind === "infra-failed" && error.message.includes("DATABASE_URL is required"), ); const postgresContract = postgresMigrationContract(); assert.equal(postgresContract.latestMigrationId, "003_v01_hwlab_manual_dispatch"); assert.ok(Array.isArray(postgresContract.requiredTables)); assert.ok(postgresContract.requiredTables.includes("agentrun_schema_migrations")); assert.ok(postgresContract.requiredTables.includes("agentrun_runs")); assert.ok(postgresContract.requiredTables.includes("agentrun_events")); assert.ok(postgresContract.requiredTables.includes("agentrun_sessions")); assert.ok(postgresContract.requiredTables.includes("agentrun_runner_jobs")); return { name: "redaction-postgres", tests: ["redaction", "postgres-store-contract"] }; }; export default selfTest;