Repository navigation
feat(e2e): verify the migration Oracle with reference and broken applications #1581
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
Open
tobyhede
wants to merge
27
commits into
feat/migration-harness-no-rewrite
from
feat/migration-harness-selftest
+852
−56
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a42006d
feat(e2e): prove migration Oracle with reference and broken applications
tobyhede 940fee2
chore(e2e): merge no-rewrite store provisioning correction
tobyhede e21d031
fix(e2e): cover tarball and denied-access self-test paths
tobyhede 2a6d829
Merge branch 'feat/migration-harness-no-rewrite' into feat/migration-…
tobyhede e6c327e
docs(e2e): document reference migration self-test commands
tobyhede 0f92547
test(e2e): keep live Run failure diagnostics bounded
tobyhede a2a5992
fix(e2e): install system trust roots in isolated application hosts
tobyhede 9693bcd
test(e2e): probe the supervisor protected canary from migrated code
tobyhede cff9e9d
fix(e2e): reconcile reference migration acceptance with reviewed Run …
tobyhede fdc34d4
chore(e2e): carry the Git runtime into reference migration tests
tobyhede efc6ebf
Merge branch 'reconcile/no-rewrite' into reconcile/selftest
tobyhede c485447
Merge branch 'reconcile/no-rewrite' into reconcile/selftest
tobyhede 7050869
Merge branch 'reconcile/no-rewrite' into reconcile/selftest
tobyhede af734b8
Merge branch 'reconcile/no-rewrite' into reconcile/selftest
tobyhede c0a56ad
fix(e2e): classify mutation snapshot failures by cause
tobyhede 0ef3b5a
chore(e2e): merge the strace tracee attribution fix
tobyhede 1e47ee2
chore(e2e): merge the snapshot classification review fixes
tobyhede 852a1ea
fix(e2e): resolve the Stack FFI range from npm 12 array answers
tobyhede a846f0e
chore(e2e): merge the isolation Git ownership fix
tobyhede dc4c56d
chore(e2e): merge the held-descriptor observer fix
tobyhede 07ec49d
chore(e2e): integrate bounded migration validation
tobyhede 4927b35
chore(e2e): integrate supervisor frame compatibility
tobyhede fa43ab9
chore(e2e): integrate tracee lifetime repair into self-tests
tobyhede 26587ca
chore(e2e): integrate socket error classification into self-tests
tobyhede 6297779
chore(e2e): integrate friction schema into self-tests
tobyhede e5fdf39
chore(e2e): integrate explicit process tracing fix
tobyhede 813ff43
chore(e2e): integrate traced actor identity repair
tobyhede 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import 'dotenv/config' | ||
| import assert from 'node:assert/strict' | ||
| import { mkdtemp, rm } from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import { resolve } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { test } from 'vitest' | ||
| import { createIsolation } from '../isolation.mjs' | ||
| import { createRealDriver } from '../run/real-driver.mjs' | ||
| import { run } from '../run/run.mjs' | ||
|
|
||
| const keys = [ | ||
| 'CS_WORKSPACE_CRN', | ||
| 'CS_CLIENT_ID', | ||
| 'CS_CLIENT_KEY', | ||
| 'CS_CLIENT_ACCESS_KEY', | ||
| ] | ||
| const enabled = | ||
| process.env.HARNESS_LIVE === '1' && keys.every((key) => process.env[key]) | ||
| const cases = [ | ||
| ['reference', 'pass', null], | ||
| ['noop', 'behaviour', 'migration.protect-dependencies-absent'], | ||
| ['downcase', 'behaviour', 'behaviour.downcase-new-write-lookup'], | ||
| ['stale-hmac', 'behaviour', 'migration.active-hmac-absent'], | ||
| ['bigint', 'behaviour', 'behaviour.balance-decimal-string'], | ||
| ['rewrite', 'behaviour', 'no-rewrite.legacy-bytes'], | ||
| ['missing-log', 'invalid-friction-log', null], | ||
| ['legacy-ffi', 'behaviour', 'migration.protect-ffi-version'], | ||
| ['denied-app', 'pass', null], | ||
| ['denied-lifecycle', 'pass', null], | ||
| ['tree', 'pass', null], | ||
| ] as const | ||
| for (const [kind, outcome, checkId] of cases) { | ||
| test.skipIf(!enabled)( | ||
| `real Run self-test: ${kind}`, | ||
| async () => { | ||
| const output = await mkdtemp(resolve(tmpdir(), 'mh-selftest-')) | ||
| const isolation = createIsolation() | ||
| const manifest = { | ||
| stack: kind === 'tree' ? 'tree' : '^1.2.1', | ||
| guideHash: null, | ||
| } | ||
| const driver = createRealDriver({ | ||
| id: `selftest-${Date.now()}`, | ||
| root: fileURLToPath(new URL('../../..', import.meta.url)), | ||
| output, | ||
| command: '', | ||
| fakeMigration: kind === 'tree' ? 'reference' : kind, | ||
| isolation, | ||
| credentials: Object.fromEntries( | ||
| keys.map((key) => [key, process.env[key] ?? '']), | ||
| ), | ||
| manifest, | ||
| }) | ||
| try { | ||
| const report = await run({ | ||
| id: kind, | ||
| manifest, | ||
| driver, | ||
| supervision: isolation, | ||
| }) | ||
| const diagnostics = JSON.stringify({ | ||
| outcome: report.outcome, | ||
| failures: report.failures, | ||
| checks: report.evidence | ||
| .filter( | ||
| (e) => | ||
| e.kind === 'oracle-check' && Object(e.payload).passed === false, | ||
| ) | ||
| .map((e) => e.payload), | ||
| }) | ||
| assert.equal(report.outcome, outcome, diagnostics) | ||
| if (kind.startsWith('denied-')) | ||
| assert.ok( | ||
| report.evidence.some( | ||
| (e) => | ||
| e.kind === 'isolation-event' && | ||
| Object(e.payload).result === 'denied' && | ||
| Object(e.payload).decision === 'forbidden' && | ||
| Object(e.payload).resource === '/trace/canary', | ||
| ), | ||
| ) | ||
| if (checkId) | ||
| assert.equal( | ||
| Object(report.evidence.find((e) => e.checkId === checkId)?.payload) | ||
| .passed, | ||
| false, | ||
| diagnostics, | ||
| ) | ||
| if (kind === 'noop') | ||
| assert.ok( | ||
| report.evidence | ||
| .filter( | ||
| (e) => | ||
| e.kind === 'oracle-check' && | ||
| !e.checkId.startsWith('migration.'), | ||
| ) | ||
| .every((e) => Object(e.payload).passed), | ||
| ) | ||
| if (kind === 'reference') | ||
| assert.ok( | ||
| report.evidence.some( | ||
| (e) => e.checkId === 'no-rewrite.legacy-bytes', | ||
| ), | ||
| ) | ||
| } finally { | ||
| await driver.close() | ||
| await rm(output, { recursive: true, force: true }) | ||
| } | ||
| }, | ||
| 600_000, | ||
| ) | ||
| } | ||
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,77 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
| import { test } from 'vitest' | ||
| import { migrationChecks } from '../run/migration-checks.mjs' | ||
| import { run } from '../run/run.mjs' | ||
|
|
||
| for (const stale of [false, true]) { | ||
| test(`Run migration evidence ${stale ? 'rejects stale' : 'accepts removed'} boolean HMAC`, async () => { | ||
| const workspace = await mkdtemp(join(tmpdir(), 'mh-migration-')) | ||
| await mkdir(join(workspace, 'src')) | ||
| await writeFile( | ||
| join(workspace, 'src/app.mjs'), | ||
| 'import { Encryption } from "@cipherstash/stack/v3"', | ||
| ) | ||
| await writeFile( | ||
| join(workspace, 'package.json'), | ||
| JSON.stringify({ dependencies: { '@cipherstash/stack': '1.2.1' } }), | ||
| ) | ||
| await writeFile( | ||
| join(workspace, 'package-lock.json'), | ||
| JSON.stringify({ | ||
| packages: { | ||
| '': { dependencies: { '@cipherstash/stack': '1.2.1' } }, | ||
| 'node_modules/@cipherstash/stack': { | ||
| version: '1.2.1', | ||
| dependencies: { '@cipherstash/protect-ffi': '0.31.0' }, | ||
| }, | ||
| 'node_modules/@cipherstash/protect-ffi': { version: '0.31.0' }, | ||
| }, | ||
| }), | ||
| ) | ||
| try { | ||
| const report = await run({ | ||
| id: 'migration', | ||
| manifest: { guideHash: 'guide' }, | ||
| driver: { | ||
| provision: async () => {}, | ||
| installUnmigrated: async () => {}, | ||
| initializeLegacyData: async () => {}, | ||
| snapshot: async () => {}, | ||
| migrate: async () => ({ exitCode: 0 }), | ||
| friction: async () => [], | ||
| installAppHost: async () => {}, | ||
| behaviour: async () => [ | ||
| { id: 'no-rewrite.legacy-bytes', passed: true }, | ||
| ...(await migrationChecks({ | ||
| workspace, | ||
| installedWorkspace: workspace, | ||
| ffiRange: '0.31.0', | ||
| mutationSnapshot: { | ||
| dynamo: { | ||
| Item: stale | ||
| ? { active__source: 'cipher', active__hmac: 'old' } | ||
| : { active__source: 'cipher' }, | ||
| }, | ||
| }, | ||
| stackVersion: '1.2.1', | ||
| })), | ||
| ], | ||
| }, | ||
| }) | ||
| assert.equal(report.outcome, stale ? 'behaviour' : 'pass') | ||
| assert.equal( | ||
| Object( | ||
| report.evidence.find( | ||
| (e) => e.checkId === 'migration.active-hmac-absent', | ||
| )?.payload, | ||
| ).passed, | ||
| !stale, | ||
| ) | ||
| } finally { | ||
| await rm(workspace, { recursive: true, force: true }) | ||
| } | ||
| }) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { afterEach, expect, test, vi } from 'vitest' | ||
|
|
||
| const npmView = vi.hoisted(() => new Map<string, string>()) | ||
|
|
||
| vi.mock('node:child_process', () => ({ | ||
| execFile: ( | ||
| _command: string, | ||
| args: string[], | ||
| callback: (error: Error | null, result?: { stdout: string }) => void, | ||
| ) => { | ||
| const stdout = npmView.get(args.slice(1, 3).join(' ')) | ||
| if (stdout === undefined) callback(Error(`unexpected npm ${args}`)) | ||
| else callback(null, { stdout }) | ||
| }, | ||
| })) | ||
|
|
||
| const { resolveStack } = await import('../run/stack-source.mjs') | ||
|
|
||
| afterEach(() => npmView.clear()) | ||
|
|
||
| // npm 12 answers `npm view <spec> <field> --json` with an array even when the | ||
| // spec names one exact version; older npm answers with the bare value. | ||
| test.each([ | ||
| ['npm 10 bare values', '"1.2.1"', '"0.33.0"'], | ||
| ['npm 12 single-element arrays', '["1.2.1"]', '["0.33.0"]'], | ||
| ])('resolves a registry Stack from %s', async (_npm, version, ffi) => { | ||
| npmView.set('@cipherstash/stack@^1.2.1 version', version) | ||
| npmView.set( | ||
| '@cipherstash/stack@1.2.1 dependencies.@cipherstash/protect-ffi', | ||
| ffi, | ||
| ) | ||
| await expect( | ||
| resolveStack({ source: '^1.2.1', root: '/', output: '/' }), | ||
| ).resolves.toEqual({ version: '1.2.1', install: '1.2.1', ffiRange: '0.33.0' }) | ||
| }) | ||
|
|
||
| test('rejects an ambiguous FFI dependency answer', async () => { | ||
| npmView.set('@cipherstash/stack@1.2.1 version', '"1.2.1"') | ||
| npmView.set( | ||
| '@cipherstash/stack@1.2.1 dependencies.@cipherstash/protect-ffi', | ||
| '["0.33.0","0.34.0"]', | ||
| ) | ||
| await expect( | ||
| resolveStack({ source: '1.2.1', root: '/', output: '/' }), | ||
| ).rejects.toThrow('Could not resolve Stack FFI dependency') | ||
| }) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor · P2 The Migrator and App Host both run the denied install hook. A Migrator denial satisfies this assertion even if the App Host skips the hook or loses its event. Require actor
app-hostand stageapp-host-installin the matching denial.Source: fresh Codex reviewer