Files
orca/tests/e2e/cross-version-wire/release-module-locations.ts
T
Neil bdd997f71f test(cross-version): load moved modules from wherever each release defines them (#37297)
* test(cross-version): load moved modules from wherever each release defines them

v1.4.246 is the first release cut after #36909, #36979, #37036 and #37070 moved
the agent-session modules, so suites that imported the old paths from the
newest release failed with ERR_MODULE_NOT_FOUND for every PR running
cross-version wire. importReleaseCheckoutModule now resolves a moved module to
the path the checked-out release ships, from one table of current and earlier
locations, so both the rolling baseline and older pinned refs load. The
released-chat writers drop their own per-module existsSync fallbacks for it.

v1.4.246 also ships outcome storage, so it reads chats this build writes and
closes its own rows with the outcomes marker. The downgrade test pins its
refusing window to the two releases before outcome storage, and the upgrade
test leaves the marker to the outcome reader, which restoreJournal checks.

* test(cross-version): find a moved module by name in the release instead of a path table

A table of earlier paths is a list of stale src literals the path-literal ratchet rightly refuses, and needs an entry for every future move. The release checkout itself says where it ships each module: the one file with that name under the same source root. Prunes the three released-chat-writers entries the ratchet baseline grandfathered.

* test(cross-version): pin the chat-upgrade writers to the releases before outcome storage

v1.4.246 keeps a chat in outcome tables, so its rows hold only the marker and there is no row upgrade to carry on; the newest release stays the reader this build must match.
2026-11-01 20:19:25 -08:00

54 lines
1.7 KiB
TypeScript

import { existsSync, readdirSync } from 'node:fs'
import { join, posix } from 'node:path'
export type ReleaseTree = {
exists: (rootRelativePath: string) => boolean
/** Root-relative forward-slash paths of every file under `directory`. */
list: (directory: string) => readonly string[]
}
const listings = new Map<string, readonly string[]>()
function checkoutTree(root: string): ReleaseTree {
return {
exists: (path) => existsSync(join(root, path)),
list: (directory) => {
const key = join(root, directory)
let files = listings.get(key)
if (!files) {
files = existsSync(key)
? readdirSync(key, { recursive: true, encoding: 'utf8' }).map((entry) =>
posix.join(directory, entry.split('\\').join('/'))
)
: []
listings.set(key, files)
}
return files
}
}
}
/**
* Where the release under `root` defines the module a suite names. Suites name main's path; a
* release cut before a folder move ships the module elsewhere under the same source root, so the
* one file there with its name is that module. Missing or ambiguous names pass through and fail
* at import, naming the path the suite asked for.
*/
export function releaseModuleLocation(
root: string,
rootRelativePath: string,
tree: ReleaseTree = checkoutTree(root)
): string {
const named = rootRelativePath
.replace(/^[/\\]+/, '')
.split('\\')
.join('/')
const sourceRoot = named.split('/').slice(0, 2).join('/')
if (tree.exists(named) || !sourceRoot.startsWith('src/')) {
return named
}
const name = posix.basename(named)
const moved = tree.list(sourceRoot).filter((path) => posix.basename(path) === name)
return moved.length === 1 ? moved[0]! : named
}