Repository navigation
test(vscode): add opt-in Inspect and Start controls for packaged repair (#4651) #16243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
EffortlessSteven
wants to merge
2
commits into
main
Choose a base branch
from
test/4651-vsix-repair-start
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
editors/vscode/test/suite/packaged_repair_start.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!)); | ||
|
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); | ||
|
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); | ||
|
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}`); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.