Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions editors/vscode/test/requiredJourneys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ export const PACKAGED_SERVER_HANDSHAKE: RequiredJourney = {
test: 'accepts the real packaged server through initialize and shutdown',
};

export const PACKAGED_REPAIR_START: RequiredJourney = {
file: 'packaged_repair_start.test.ts',
suite: 'Packaged Repair Start',
test: 'distinguishes inspection from an enabled Start for the current gap',
};

export const ALL_REQUIRED_JOURNEYS: RequiredJourney[] = [
PACKAGED_TRUST_TRUSTED,
PACKAGED_TRUST_UNTRUSTED,
...REAL_SERVER_JOURNEYS,
PACKAGED_SERVER_HANDSHAKE,
PACKAGED_REPAIR_START,
];

export function fullTitle(journey: RequiredJourney): string {
Expand Down
51 changes: 39 additions & 12 deletions editors/vscode/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as path from 'path';
import * as fs from 'fs';
import { execFileSync, spawn } from 'child_process';
import { createHash } from 'crypto';
import { runTests } from '@vscode/test-electron';
import { downloadVSCodeWithRetry, requireEditorDisplay, resetEditorSetupEvidence, verifyHostPrerequisites } from './hostPrerequisites';
import { stageGenuineActionableQueue } from './actionableQueueFixture';
import { REQUIRED_TITLE_SEPARATOR, requiredJourneyTitles } from './requiredJourneys';
import { fullTitle, PACKAGED_REPAIR_START, REQUIRED_TITLE_SEPARATOR, requiredJourneyTitles } from './requiredJourneys';
import { finalizeHostRun, resetHostLogDir, resolveUserDataDir } from './hostDiagnostics';

function runGit(workspacePath: string, args: string[]): string {
Expand Down Expand Up @@ -205,8 +206,33 @@ export async function main(runtime: TestHostRuntime = defaultTestHostRuntime) {
try {
resetEditorSetupEvidence(artifactRoot);
resetHostLogDir(userDataPath);
const repairStartCase = process.env.RIPR_TEST_REPAIR_START_CASE;
const repairStart = repairStartCase !== undefined;
const testServerPath = process.env.RIPR_TEST_SERVER_PATH;
const packagedServerPath = process.env.RIPR_TEST_PACKAGED_SERVER_PATH;
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
const workspaceTrustMode = parseWorkspaceTrustMode(process.env.RIPR_TEST_WORKSPACE_TRUST);
const repairWorkspace = process.env.RIPR_TEST_REPAIR_START_WORKSPACE;
const suppliedExtension = process.env.RIPR_TEST_EXTENSION_PATH;
if (repairStart) {
const serverDigest = process.env.RIPR_TEST_PACKAGED_SERVER_SHA256 ?? '';
if (repairStartCase !== 'called' && repairStartCase !== 'uncalled') {
throw new Error('RIPR_TEST_REPAIR_START_CASE must be called or uncalled');
}
if (workspaceTrustMode !== 'trusted' || process.env.RIPR_TEST_MULTIROOT_ONLY === '1'
|| !process.env.RIPR_TEST_ARTIFACT_ROOT || !repairWorkspace || !path.isAbsolute(repairWorkspace)
|| !suppliedExtension || !path.isAbsolute(suppliedExtension) || !testServerPath
|| !path.isAbsolute(testServerPath) || testServerPath !== packagedServerPath
|| !/^[a-f0-9]{64}$/.test(serverDigest)) {
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
throw new Error('repair Start proof requires a trusted isolated profile, staged fixture, supplied extension and digest-pinned packaged server');
}
const actualDigest = createHash('sha256').update(fs.readFileSync(testServerPath)).digest('hex');
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
if (actualDigest !== serverDigest) {
throw new Error('repair Start proof server does not match the supplied SHA-256');
}
process.env.RIPR_REPO_EXPOSURE_SEAM_LIMIT = '0';
}
const extensionDevelopmentPath = path.resolve(
process.env.RIPR_TEST_EXTENSION_PATH ?? path.resolve(__dirname, '../../')
suppliedExtension ?? path.resolve(__dirname, '../../')
);
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const templatePath = path.resolve(
Expand All @@ -216,9 +242,8 @@ export async function main(runtime: TestHostRuntime = defaultTestHostRuntime) {
const cachePath = path.join(artifactRoot, 'vscode-test-cache');
const runId = String(process.pid);
const extensionsPath = path.join(artifactRoot, 'vscode-test-extensions', runId);
const workspacePath = path.join(artifactRoot, 'workspace');
const baseRef = stageIntegrationWorkspace(templatePath, workspacePath);
const workspaceTrustMode = parseWorkspaceTrustMode(process.env.RIPR_TEST_WORKSPACE_TRUST);
const workspacePath = repairWorkspace && repairStart ? repairWorkspace : path.join(artifactRoot, 'workspace');
const baseRef = repairStart ? 'main' : stageIntegrationWorkspace(templatePath, workspacePath);
process.env.RIPR_TEST_BASE_REF = baseRef;
fs.mkdirSync(cachePath, { recursive: true });
fs.mkdirSync(extensionsPath, { recursive: true });
Expand All @@ -232,7 +257,7 @@ export async function main(runtime: TestHostRuntime = defaultTestHostRuntime) {
runtime.requireEditorDisplay(process.platform, process.env);
const vscodeExecutablePath = await runtime.downloadVSCode(cachePath, extensionDevelopmentPath);
await runtime.verifyHostPrerequisites(vscodeExecutablePath, artifactRoot);
if (workspaceTrustMode === 'trusted' && process.env.RIPR_TEST_MULTIROOT_ONLY !== '1'
if (!repairStart && workspaceTrustMode === 'trusted' && process.env.RIPR_TEST_MULTIROOT_ONLY !== '1'
&& !process.env.RIPR_TEST_ACTIONABLE_QUEUE_ROOT) {
process.env.RIPR_TEST_ACTIONABLE_QUEUE_ROOT = await runtime.stageGenuineActionableQueue(
path.resolve(__dirname, '../../../../'), path.join(artifactRoot, `actionable-queue-${runId}`)
Expand All @@ -251,7 +276,6 @@ export async function main(runtime: TestHostRuntime = defaultTestHostRuntime) {
'--user-data-dir',
userDataPath,
];
const testServerPath = process.env.RIPR_TEST_SERVER_PATH;
if (testServerPath) {
const userSettingsPath = path.join(userDataPath, 'User');
fs.mkdirSync(userSettingsPath, { recursive: true });
Expand All @@ -261,19 +285,22 @@ export async function main(runtime: TestHostRuntime = defaultTestHostRuntime) {
'ripr.server.path': testServerPath,
'ripr.server.autoDownload': false,
'ripr.baseRef': baseRef,
'ripr.check.mode': 'draft',
'ripr.check.mode': repairStart ? 'deep' : 'draft',
'ripr.seamDiagnostics': true,
'ripr.diagnosticProfile': 'actionable',
'ripr.diagnosticProfile': repairStart ? 'full' : 'actionable',
'security.workspace.trust.enabled': workspaceTrustMode !== 'trusted',
}, null, 2)}\n`
);
}

if (process.env.RIPR_TEST_MULTIROOT_ONLY !== '1') {
if (repairStart) {
process.env.RIPR_TEST_GREP = `^${PACKAGED_REPAIR_START.suite} `;
process.env.RIPR_TEST_REQUIRE_RAN = fullTitle(PACKAGED_REPAIR_START);
} else if (process.env.RIPR_TEST_MULTIROOT_ONLY !== '1') {
process.env.RIPR_TEST_REQUIRE_RAN = requiredJourneyTitles(
workspaceTrustMode,
testServerPath,
process.env.RIPR_TEST_PACKAGED_SERVER_PATH
packagedServerPath
).join(
REQUIRED_TITLE_SEPARATOR
);
Expand All @@ -292,7 +319,7 @@ export async function main(runtime: TestHostRuntime = defaultTestHostRuntime) {
// The multi-root host greps a different suite, so the main host's required
// journeys are not registered there.
delete process.env.RIPR_TEST_REQUIRE_RAN;
if (workspaceTrustMode === 'trusted') {
if (!repairStart && workspaceTrustMode === 'trusted') {
// Same test-host lane, separate empty profile: other suites open files,
// mutate configuration and restart servers, which would mask ambiguity.
if (!testServerPath || !fs.existsSync(testServerPath)) {
Expand Down
70 changes: 70 additions & 0 deletions editors/vscode/test/suite/host_setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from 'assert';
import { createHash } from 'crypto';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
Expand All @@ -14,6 +15,8 @@ suite('VS Code test host setup', () => {
'RIPR_TEST_MULTIROOT_ONLY', 'RIPR_TEST_ACTIONABLE_QUEUE_ROOT',
'RIPR_TEST_BASE_REF', 'RIPR_TEST_CLIPBOARD_CAPTURE_PATH',
'RIPR_TEST_SERVER_PATH', 'RIPR_TEST_PACKAGED_SERVER_PATH',
'RIPR_TEST_PACKAGED_SERVER_SHA256', 'RIPR_TEST_REPAIR_START_CASE',
'RIPR_TEST_REPAIR_START_WORKSPACE', 'RIPR_REPO_EXPOSURE_SEAM_LIMIT',
'RIPR_TEST_REQUIRE_RAN', 'RIPR_TEST_MULTIROOT', 'RIPR_TEST_GREP',
'RIPR_TEST_MULTIROOT_PATH', 'RIPR_TEST_MULTIROOT_RECEIPT',
];
Expand Down Expand Up @@ -101,6 +104,73 @@ suite('VS Code test host setup', () => {
assert.strictEqual(retention.error.message, message);
}

test('a focused repair Start run requires an explicit packaged server', async () => {
process.env.RIPR_TEST_REPAIR_START_CASE = 'called';
await main(runtime);
assert.deepStrictEqual(events, []);
assertFailure('repair Start proof requires a trusted isolated profile, staged fixture, supplied extension and digest-pinned packaged server');
});

function configureRepairStartRun() {
const fixture = path.join(root, 'fixture');
const extension = path.join(root, 'extension');
fs.mkdirSync(fixture);
fs.writeFileSync(path.join(fixture, 'sentinel'), 'pre-staged fixture');
process.env.RIPR_TEST_REPAIR_START_CASE = 'uncalled';
process.env.RIPR_TEST_REPAIR_START_WORKSPACE = fixture;
process.env.RIPR_TEST_EXTENSION_PATH = extension;
process.env.RIPR_TEST_PACKAGED_SERVER_PATH = process.env.RIPR_TEST_SERVER_PATH;
const serverBytes = fs.readFileSync(process.env.RIPR_TEST_SERVER_PATH!);
process.env.RIPR_TEST_PACKAGED_SERVER_SHA256 = createHash('sha256').update(serverBytes).digest('hex');
return { fixture, extension };
}

test('a focused repair Start run refuses the wrong server digest before launching the host', async () => {
configureRepairStartRun();
process.env.RIPR_TEST_PACKAGED_SERVER_SHA256 = '0'.repeat(64);
const staleSetup = path.join(artifactRoot, 'setup-editor-host.json');
const staleLog = path.join(artifactRoot, 'vscode-test-user-data', 'logs', 'old-host.log');
fs.mkdirSync(path.dirname(staleLog), { recursive: true });
fs.writeFileSync(staleSetup, '{"status":"pass","nonce":"old"}');
fs.writeFileSync(staleLog, 'old host proof');
await main(runtime);
assert.deepStrictEqual(events, []);
assert.ok(!fs.existsSync(staleSetup));
assert.ok(!fs.existsSync(staleLog));
assertFailure('repair Start proof server does not match the supplied SHA-256');
});

test('a focused repair Start run uses only the supplied fixture and required suite', async () => {
const { fixture, extension } = configureRepairStartRun();
runtime.downloadVSCode = async (_cache, selectedExtension) => {
assert.strictEqual(selectedExtension, extension);
return vscodeExecutablePath;
};
runtime.runTests = async (options) => {
events.push('host');
assert.strictEqual(options.extensionDevelopmentPath, extension);
assert.strictEqual(options.launchArgs?.[1], fixture);
assert.strictEqual(process.env.RIPR_TEST_GREP, '^Packaged Repair Start ');
assert.strictEqual(process.env.RIPR_TEST_REQUIRE_RAN,
'Packaged Repair Start distinguishes inspection from an enabled Start for the current gap');
const settings = JSON.parse(fs.readFileSync(path.join(artifactRoot, 'vscode-test-user-data',
'User', 'settings.json'), 'utf8'));
assert.strictEqual(settings['ripr.server.path'], process.env.RIPR_TEST_PACKAGED_SERVER_PATH);
assert.strictEqual(settings['ripr.server.autoDownload'], false);
assert.strictEqual(settings['ripr.baseRef'], 'main');
assert.strictEqual(settings['ripr.check.mode'], 'deep');
assert.strictEqual(settings['ripr.diagnosticProfile'], 'full');
assert.strictEqual(process.env.RIPR_REPO_EXPOSURE_SEAM_LIMIT, '0');
return 0;
};

await main(runtime);
assert.deepStrictEqual(events, ['host']);
assert.deepStrictEqual(exits, []);
assert.strictEqual(fs.readFileSync(path.join(fixture, 'sentinel'), 'utf8'), 'pre-staged fixture');
assert.ok(!fs.existsSync(path.join(artifactRoot, 'workspace')));
});

test('a rejected host download invokes zero producers and retains the original failure', async () => {
fs.mkdirSync(artifactRoot);
fs.writeFileSync(path.join(artifactRoot, 'setup-editor-host.json'), '{"status":"pass","nonce":"old"}');
Expand Down
111 changes: 111 additions & 0 deletions editors/vscode/test/suite/packaged_repair_start.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import * as assert from 'assert';
import { createHash } from 'crypto';
import { promises as fs } from 'fs';
import * as path from 'path';
import { setTimeout as delay } from 'timers/promises';
import * as vscode from 'vscode';

const GAP = 'gap:rust:src/lib.rs:loyalty_price:predicate_boundary:predicate:member_years==5';
const TARGET = 'tests/loyalty_price.rs';
const START = 'ripr.copyAgentRepairCommand';

function enabledCommand(action: vscode.CodeAction | vscode.Command): vscode.Command | undefined {
if (typeof action.command === 'string') {
return action as vscode.Command;
}
return (action as vscode.CodeAction).disabled ? undefined : action.command;
}

suite('Packaged Repair Start', () => {
test('distinguishes inspection from an enabled Start for the current gap', async function () {
const kind = process.env.RIPR_TEST_REPAIR_START_CASE;
if (kind === undefined) {
this.skip();
return;
}
this.timeout(120_000);
assert.ok(kind === 'called' || kind === 'uncalled');
assert.ok(vscode.workspace.isTrusted);
const workspace = vscode.workspace.workspaceFolders?.[0];
assert.ok(workspace);
assert.strictEqual(await fs.realpath(workspace.uri.fsPath),
await fs.realpath(process.env.RIPR_TEST_REPAIR_START_WORKSPACE!));
const extension = vscode.extensions.getExtension('EffortlessMetrics.ripr');
assert.ok(extension);
assert.strictEqual(await fs.realpath(extension.extensionPath),
await fs.realpath(process.env.RIPR_TEST_EXTENSION_PATH!));
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved

const uri = vscode.Uri.joinPath(workspace.uri, 'src/lib.rs');
const config = vscode.workspace.getConfiguration('ripr', uri);
const server = config.get<string>('server.path');
assert.ok(server && path.isAbsolute(server));
assert.strictEqual(server, process.env.RIPR_TEST_PACKAGED_SERVER_PATH);
assert.strictEqual(config.get('server.autoDownload'), false);
assert.strictEqual(config.get('baseRef'), 'main');
assert.strictEqual(config.get('check.mode'), 'deep');
assert.strictEqual(config.get('diagnosticProfile'), 'full');
const serverDigest = createHash('sha256').update(await fs.readFile(server)).digest('hex');
assert.strictEqual(serverDigest, process.env.RIPR_TEST_PACKAGED_SERVER_SHA256);

await extension.activate();
await vscode.window.showTextDocument(await vscode.workspace.openTextDocument(uri));
await vscode.commands.executeCommand('ripr.refreshDiagnostics');
const expectedLine = kind === 'uncalled' ? 5 : 9;
const deadline = Date.now() + 60_000;
while (Date.now() < deadline) {
const diagnostic = vscode.languages.getDiagnostics(uri).find((entry) =>
entry.source === 'ripr' && entry.code === 'ripr-seam-ungripped'
&& entry.range.start.line === expectedLine);
if (diagnostic) {
const actions = await vscode.commands.executeCommand<Array<vscode.CodeAction | vscode.Command>>(
'vscode.executeCodeActionProvider', uri, diagnostic.range);
const commands = (actions ?? []).map(enabledCommand).filter((command) => command !== undefined);
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
const inspection = commands.find((command) => command.command === 'ripr.copyContext'
&& command.arguments?.[0]?.label === 'repair_card');
if (inspection) {
// A freshly copied current card establishes that the same provider
// answered for this spot before we test the absence of enabled Start.
await vscode.env.clipboard.writeText('ripr-repair-card-sentinel');
await vscode.commands.executeCommand(inspection.command, ...(inspection.arguments ?? []));
const copied = await vscode.env.clipboard.readText();
assert.notStrictEqual(copied, 'ripr-repair-card-sentinel', 'Inspect must copy a card');
const card = JSON.parse(copied);
assert.strictEqual(card.subject.canonical_gap_id, GAP);
assert.strictEqual(card.snapshot.currentness, 'current');
assert.strictEqual(card.selected_target.file, TARGET);
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
const seam: unknown = card.subject.seam_id;
assert.ok(typeof seam === 'string' && seam.length > 0);

const starts = commands.filter((command) => command.command === START);
assert.strictEqual(starts.length, kind === 'uncalled' ? 1 : 0,
`unexpected enabled Start actions for ${kind} ${seam}`);
const start = starts[0];
let copiedStart: string | null = null;
if (start) {
await vscode.env.clipboard.writeText('ripr-repair-start-sentinel');
await vscode.commands.executeCommand(start.command, ...(start.arguments ?? []));
copiedStart = await vscode.env.clipboard.readText();
assert.ok(copiedStart.startsWith('ripr agent repair --root '), copiedStart);
assert.ok(copiedStart.endsWith(` --seam-id ${seam} --phase before`), copiedStart);
} else {
assert.strictEqual(card.instruction.state, 'static_limitation');
assert.strictEqual(card.next_action, null);
}

// The caller joins this observation with artifact custody and
// fixture revisions before producing the existing parity receipt.
const observation = { case: kind, gap: GAP, seam, target: TARGET,
currentness: card.snapshot.currentness, enabled_start: starts.length, copied_start: copiedStart,
server, server_sha256: serverDigest, extension_path: extension.extensionPath,
extension_version: extension.packageJSON.version, vscode_version: vscode.version,
node_version: process.versions.node, platform: process.platform, arch: process.arch };
await fs.writeFile(path.join(process.env.RIPR_TEST_ARTIFACT_ROOT!, 'repair-start-observation.json'),
`${JSON.stringify(observation, null, 2)}\n`, { flag: 'wx' });
return;
}
}
await delay(250);
}
assert.fail(`missing current loyalty_price inspection for ${kind}`);
});
});