Files
orca/config/scripts/test-runtime/sqlite-admission/vitest-sqlite-runtime-scan.mjs
e516efcb61 Keep finished agents marked Done while their panes sleep (#41793)
* Remove finished-agent retention and keep sleeping status with panes

* Fix legacy pane projection and sleeping-agent regression fixtures

* Cover sleeping display-only status in parked terminal coverage

* Keep pane conversation identity only across continuous agent observations

* Remove duplicate import and keep sleep fixtures type checked

* Preserve conversation boundaries across replays and inherited clocks

* Cover conversation map stability across a large status batch

* Bound conversation capacity work to changed pane owners

* Pass capacity classifiers their layout input directly

* Finalize conversation provenance once per status batch

* Keep paired snapshot tests focused on observable outcomes

* Type the conversation provenance test fixtures explicitly

* Consolidate agent session imports after main merge

* Preserve provider replacement evidence when resetting conversation continuity

* Separate retention deletion from sleeping agent display

* Restore migration row bucket comparison

* Skip unusable pane identities before title ownership lookups

* Refresh conversation titles when their owning pane changes

* Update completion test sound mock after module move

* Keep finished agent status with sleeping panes and update agents by key

* Forward sleeping pane status and scope paired tab updates

* Preserve keyed selectors and compiler invalidation through final checks

* Keep bound store hooks visible to the compiler and measure published links

* Install provenance measurement before factory capture

* Use a static store hook and name presentation metadata once

* Preserve keyed freshness and atomic agent status publication

* Preserve remote folder dashboard regression after suite retirement

* Model pane wake before live identity reobservation in regression

* Share keyed row transactions and finish main integration

* Align runtime fixtures with keyed agent status reads

* Keep status projections addressed and activity summaries current

* Retire empty workspace status summaries after their source leaves

* Use the standard store fixture for parked terminal graph tests

* Align status fixtures with app types and a fixed test clock

* test: capture stored terminal render failure details

* Read terminal titles and completion prompts from keyed agent status

* Compose foreground agent state in worktree test stores

* test: complete lineage list agent state fixture

* Keep sleeping completion when retiring process authority

* Run durable agent-hook status tests with Node SQLite

* Preserve sleeping Done when renderer retires its process

* Update terminal fixtures for process retirement

* Read sleeping pane resume sources by key

* Bind sleep capture fixture to its live panes

* Pass the pane tree to the sleep capture fixture graph

* Preserve accepted completion identity through sleep

* Pass a nullable title to the status classifier

* Resolve accepted host status once and preserve delivery order

* Drop published sleep status when its host owner retires

* Use the supported remote completion test envelope

* Preserve published activity when filling completed status

* Update imports for main module moves

* Remove an unreachable native chat owner comparison

* Read host and unread card inputs by address instead of per root

A host-scoped sidebar card re-read every root's row and acknowledgement on
any store write, so one card with many sleeping roots paid for other
workspaces' updates. Card host filtering, the summary pill's unread state
and the workspace unread gate now first compare the workspace's projected
row revision and the changed keys of the tab-keyed layout/PTY maps and
the acknowledgement record. Only an addressed change re-reads the roots.
Acknowledge and unacknowledge annotate their writes so readers can skip
keys they don't show.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Correct sleeping pane test imports after module moves

* Combine duplicate subscription test imports

* Record addressed acknowledgement deletions on row drops

* Type subscription fixture key set for string readers

* Keep accepted updates complete after observer failures

* Seed the send picker with its SSH terminal identity

* perf(layout): skip unused normalization reports in pane commands (#42615)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Clarify cleanup pinning and ignored-file protection (#42616)

* test: remove 55 low-value suites and assertion driver (#42605)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>

* fix(skills): skip Claude sync scratch folders during skill discovery (#42610)

Claude Code parks replaced skill copies in `.trash` and in-progress syncs
in `.staging` under its skills roots. Discovery walked into both, so each
synced skill showed up as duplicates. Prune those directory names in the
native file walk and in the generated WSL `find` command.

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>

* test: remove 78 low-value suites and trim redundant cases (#42621)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>

* Keep a host card's unchanged agent rows after filtering out another host's pane

Re-lineage clones every row once a host-scoped card filters a row out, so an unrelated pane's status write rebuilt the card's row array and re-ran its signal and rollup memos. Reuse unchanged rows as main's sidebar row selector does.

* Seed the Copy Session ID shortcut test through keyed agent status

* Seed the graph payload partition test through keyed agent status

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: OrcaWin <alpha-eng@stably.ai>
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
Co-authored-by: BingZ <zzb@gxsmjx.com>
Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-11-15 11:38:40 -08:00

193 lines
7.1 KiB
JavaScript

import { createHash } from 'node:crypto'
import { mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { basename, dirname, isAbsolute, join, posix, relative, resolve } from 'node:path'
import { UNIT_INCLUDE } from '../../ci/unit-selection/dependency-graph/ci-unit-files.mjs'
const require = createRequire(new URL('../../vitest-sqlite-runtime-scan.mjs', import.meta.url))
const root = resolve(import.meta.dirname, '../../../..')
// Keyed by checkout, since worktrees can share one node_modules.
const CACHE_FILE = join(
root,
'node_modules',
'.cache',
`orca-vitest-sqlite-runtime-${createHash('sha256').update(root).digest('hex').slice(0, 16)}.json`
)
const SOURCE_EXTENSION = /\.[cm]?[jt]sx?$/
const SQLITE_HARNESSES = new Set([
'persistence-test-harness',
'agent-session-record-store-test-harness',
'structured-agent-session-rest-test-rig',
'journal-host-database-test-support',
'terminal-topology-profile-fixture',
'acknowledged-terminal-tab-retirement-fixture',
'last-status.test-fixtures',
'server-hook-root.test-fixtures',
// Opens the index read-only after the indexer closes; Bun's macOS SQLite refuses a WAL file then.
'session-search-indexer-test-fixture',
'session-search-index-test-fixture',
'session-search-engine-test-fixture'
])
export const SQLITE_MODULES = [
'src/main/sqlite/sync-database',
'src/main/agent-hooks/server/agent-hook-server',
'src/main/ai-vault-search/storage/session-search-schema',
'src/main/ai-vault-search/storage/session-search-store',
'src/main/persistence/profile-state/profile-state-sqlite-authority',
'src/main/native-chat/agent-session-journal/database/journal-host-database',
'src/main/runtime/orchestration/db',
'src/main/runtime/orchestration/db/orchestration-db',
'src/main/runtime/agent-session/structured-agent-session-runtime',
'src/main/runtime/agent-session/records/agent-session-record-store-slot'
]
const SQLITE_MODULE_PATHS = new Set(SQLITE_MODULES.map((module) => resolve(root, module)))
// A cheap superset of the parse below; a bare 'db' would match nearly every file.
const SQLITE_MODULE_NAMES = [
...SQLITE_HARNESSES,
...SQLITE_MODULES.map((module) => basename(module))
].filter((name) => name !== 'db')
const DB_MODULE_SPECIFIER = /\/db(?:\.[cm]?[jt]sx?)?['"]/
function namesSqliteModule(source) {
return (
SQLITE_MODULE_NAMES.some((name) => source.includes(name)) || DB_MODULE_SPECIFIER.test(source)
)
}
/** Type-only names do not erase a default binding or an empty import's side effects. */
export function importsSqliteRuntime(file, source) {
if (!namesSqliteModule(source)) {
return false
}
// Loaded on demand so a warm cache skips the compiler entirely.
const ts = require('typescript-api')
const module = ts.createSourceFile(file, source, ts.ScriptTarget.Latest)
return module.statements.some((statement) => {
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
return false
}
const clause = statement.importClause
const bindings = clause?.namedBindings
if (
clause?.isTypeOnly ||
(!clause?.name &&
bindings &&
ts.isNamedImports(bindings) &&
bindings.elements.length > 0 &&
bindings.elements.every((name) => name.isTypeOnly))
) {
return false
}
const specifier = statement.moduleSpecifier.text.replace(SOURCE_EXTENSION, '')
return (
SQLITE_HARNESSES.has(basename(specifier)) ||
SQLITE_MODULE_PATHS.has(resolve(root, dirname(file), specifier))
)
})
}
function readCache(version) {
try {
const cache = JSON.parse(readFileSync(CACHE_FILE, 'utf8'))
return cache.version === version && cache.files && typeof cache.files === 'object'
? cache.files
: {}
} catch {
return {}
}
}
function walkFiles(directory, files) {
let entries
try {
entries = readdirSync(resolve(root, directory), { withFileTypes: true })
} catch {
return
}
for (const entry of entries) {
const path = `${directory}/${entry.name}`
if (!entry.isDirectory()) {
files.push(path)
} else if (entry.name !== 'node_modules' && entry.name !== '.git') {
// Vitest's defaultExclude, pruned instead of matched per file.
walkFiles(path, files)
}
}
}
/** UNIT_INCLUDE files as repo-relative paths; a plain walk is several times faster than fs.globSync. */
export function listUnitTestFiles() {
const files = []
for (const base of new Set(UNIT_INCLUDE.map((pattern) => pattern.split('/**')[0]))) {
walkFiles(base, files)
}
return files.filter((file) => UNIT_INCLUDE.some((pattern) => posix.matchesGlob(file, pattern)))
}
// Match Vitest's case-insensitive path substrings, also stripping :line so the scan never misses selected tests.
export function matchesRunFilter(file, filters) {
const testFile = file.toLowerCase()
const absolute = resolve(root, file).replaceAll('\\', '/')
return filters.some((raw) =>
[raw, raw.replace(/(?::\d+)+$/, '')].some((filter) => {
const slashed = filter.replaceAll('\\', '/')
const relativePath = relative(process.cwd(), filter).replaceAll('\\', '/')
return (
(isAbsolute(filter) && absolute.startsWith(slashed)) ||
testFile.includes(slashed.toLowerCase()) ||
testFile.includes(relativePath.toLowerCase())
)
})
)
}
// Classify direct SQLite/harness imports only among tests the CLI filters can select.
export function findSqliteRuntimeTests({ filters } = {}) {
// Reuse unchanged verdicts; full test-source scan costs about a second.
const version = createHash('sha256')
.update(readFileSync(import.meta.filename))
.digest('hex')
const cached = readCache(version)
const scoped = Boolean(filters?.length)
const candidates = listUnitTestFiles()
const files = {}
let changed = false
for (const path of scoped
? candidates.filter((file) => matchesRunFilter(file, filters))
: candidates) {
const { mtimeMs, size } = statSync(resolve(root, path))
const entry = cached[path]
if (
Array.isArray(entry) &&
entry[0] === mtimeMs &&
entry[1] === size &&
typeof entry[2] === 'boolean'
) {
files[path] = entry
continue
}
files[path] = [
mtimeMs,
size,
importsSqliteRuntime(path, readFileSync(resolve(root, path), 'utf8'))
]
changed = true
}
if (changed || (!scoped && Object.keys(cached).length !== Object.keys(files).length)) {
try {
mkdirSync(dirname(CACHE_FILE), { recursive: true })
const temporary = `${CACHE_FILE}.${process.pid}`
// Only a full scan knows which files were deleted; a scoped one keeps verdicts it skipped.
const merged = scoped ? { ...cached, ...files } : files
writeFileSync(temporary, JSON.stringify({ version, files: merged }))
// Atomic whole-file rename prevents concurrent runs from exposing partial cache.
renameSync(temporary, CACHE_FILE)
} catch {
// The cache only saves time; the verdicts above are already complete.
}
}
return Object.keys(files)
.filter((path) => files[path][2])
.sort()
}