Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

fix(install): limit followup to target-compatible dependency resolution

Dante32ac3aff7888
diff --git a/scripts/hooks/plugin-hook-bootstrap.js b/scripts/hooks/plugin-hook-bootstrap.js
index ce42872e0..233e32980 100644
--- a/scripts/hooks/plugin-hook-bootstrap.js
+++ b/scripts/hooks/plugin-hook-bootstrap.js
@@ -7,7 +7,7 @@ const { ensureAgentDataHomeEnv } = require('../lib/agent-data-home');
const { normalizePluginRootForPlatform } = require('../lib/resolve-ecc-root');
const { readStdinRaw: readBoundedStdin, resolveMaxStdin } = require('./hook-input');
-const SHELL_PROBE_TIMEOUT_MS = 5000;
+const SHELL_PROBE_TIMEOUT_MS = 2000;
function writeStderr(stderr) {
if ((typeof stderr === 'string' || Buffer.isBuffer(stderr)) && stderr.length > 0) {
diff --git a/scripts/lib/install-lifecycle.js b/scripts/lib/install-lifecycle.js
index 5c98ddaf5..98abf8e20 100644
--- a/scripts/lib/install-lifecycle.js
+++ b/scripts/lib/install-lifecycle.js
@@ -22,10 +22,6 @@ const {
const {
prepareClaudeSkillMigration,
} = require('./install/claude-skill-migration');
-const {
- prepareLegacyAgentsMigration,
- removeLegacyAgentsFiles,
-} = require('./install/legacy-agents-migration');
const {
getLegacyAntigravityLocation,
inspectLegacyAntigravityState,
@@ -560,7 +556,6 @@ function copyContainedFile(sourcePath, destinationPath, trustedRoot, action) {
}
function removeContainedPath(destinationPath, trustedRoot, action, options = {}) {
- const { verifyQuarantined, ...removeOptions } = options;
const existingDestination = getContainedExistingPath(
destinationPath,
trustedRoot,
@@ -593,8 +588,7 @@ function removeContainedPath(destinationPath, trustedRoot, action, options = {})
}
const quarantinedStat = fs.lstatSync(quarantinePath, { bigint: true });
- if (!hasSameFileIdentity(expectedStat, quarantinedStat)
- || (verifyQuarantined && !verifyQuarantined(quarantinePath))) {
+ if (!hasSameFileIdentity(expectedStat, quarantinedStat)) {
try {
fs.renameSync(quarantinePath, finalDestination);
fs.rmdirSync(quarantineDir);
@@ -609,7 +603,7 @@ function removeContainedPath(destinationPath, trustedRoot, action, options = {})
if (quarantinedStat.isDirectory() && !options.recursive) {
fs.rmdirSync(quarantinePath);
} else {
- fs.rmSync(quarantinePath, removeOptions);
+ fs.rmSync(quarantinePath, options);
}
fs.rmdirSync(quarantineDir);
return finalDestination;
@@ -1924,9 +1918,7 @@ function prepareRepairMigration(plan, record) {
installStatePath: record.installStatePath,
statePreview: buildAdapterDerivedStatePreview(plan.statePreview, record),
};
- const initialMigration = prepareLegacyAgentsMigration(
- trustedPlan, prepareClaudeSkillMigration(trustedPlan)
- );
+ const initialMigration = prepareClaudeSkillMigration(trustedPlan);
const guardedMigration = record.adapter.id === 'codex-home'
? prepareUserOwnedFileGuard(trustedPlan, initialMigration)
: initialMigration;
@@ -2210,16 +2202,10 @@ function repairInstalledStates(options = {}) {
const legacyMigrationPaths = migration.legacyOperationsToRemove.map(
operation => operation.destinationPath
);
- const legacyAgentsMigrationPaths = migration.legacyAgentsOperationsToRemove.map(
- operation => operation.destinationPath
- );
- const hasLegacyAgentsStateMigration = migration.legacyAgentsOperationsToDetach.length > 0;
const plannedRepairs = [...new Set([
...(needsOpencodeBuild ? [opencodeBuildRepairPath] : []),
...repairOperations.map(operation => operation.destinationPath),
...legacyMigrationPaths,
- ...legacyAgentsMigrationPaths,
- ...(hasLegacyAgentsStateMigration ? [record.installStatePath] : []),
])];
if (options.dryRun) {
@@ -2235,8 +2221,7 @@ function repairInstalledStates(options = {}) {
};
}
- const hasLegacyMigration = migration.legacyOperationsToRemove.length > 0
- || hasLegacyAgentsStateMigration;
+ const hasLegacyMigration = migration.legacyOperationsToRemove.length > 0;
const repairedPaths = needsOpencodeBuild ? [opencodeBuildRepairPath] : [];
if (desiredPlan.target === 'opencode') {
const { assertOpenCodeActivationUnchanged } = require('./install/apply');
@@ -2284,8 +2269,6 @@ function repairInstalledStates(options = {}) {
}
}
}
- const legacyAgentsRepairedPaths = removeLegacyAgentsFiles(migration, record.targetRoot);
- const allRepairedPaths = [...repairedPaths, ...legacyAgentsRepairedPaths];
const changedInstalledBytes = repairOperations.length > 0
|| needsOpencodeBuild
|| hasLegacyMigration;
@@ -2297,7 +2280,7 @@ function repairInstalledStates(options = {}) {
source: { ...record.state.source },
};
assertOpenCodeRepairHookDeactivation(desiredPlan, { requireInactive: true });
- writeRefreshedInstallState(record, statePreviewToWrite, allRepairedPaths);
+ writeRefreshedInstallState(record, statePreviewToWrite, repairedPaths);
return {
adapter: record.adapter,
@@ -2305,7 +2288,7 @@ function repairInstalledStates(options = {}) {
? 'repaired'
: 'ok',
installStatePath: record.installStatePath,
- repairedPaths: allRepairedPaths,
+ repairedPaths,
plannedRepairs: [],
stateRefreshed: true,
warnings: desiredPlan.warnings,
@@ -2323,7 +2306,6 @@ function repairInstalledStates(options = {}) {
} finally {
if (releaseSettingsLock) releaseSettingsLock();
}
-
};
if (record.adapter.target !== 'opencode' || options.dryRun) return performRepair();
let repairResult;
@@ -2346,7 +2328,6 @@ function repairInstalledStates(options = {}) {
repairResult = performRepair(lease);
return repairResult;
});
-
} catch (error) {
if (repairResult?.status === 'error') {
return { ...repairResult, releaseError: error.message };
@@ -2563,7 +2544,6 @@ module.exports = {
buildDoctorReport,
discoverInstalledStates,
normalizeTargets,
- removeContainedPath,
repairInstalledStates,
uninstallInstalledStates
};
diff --git a/scripts/lib/install-targets/claude-home.js b/scripts/lib/install-targets/claude-home.js
index 0a6cfea44..2de35ec58 100644
--- a/scripts/lib/install-targets/claude-home.js
+++ b/scripts/lib/install-targets/claude-home.js
@@ -4,6 +4,7 @@ const {
HOME_INSTALL_EXCLUDED_SOURCE_PATHS,
createInstallTargetAdapter,
createRemappedOperation,
+ isForeignPlatformPath,
normalizeRelativePath,
planClaudeHooksOperations,
} = require('./helpers');
@@ -67,9 +68,7 @@ module.exports = createInstallTargetAdapter({
return modules.flatMap(module => {
const paths = Array.isArray(module.paths) ? module.paths : [];
return paths
-
- .filter(adapter.supportsSourcePath)
-
+ .filter(p => !isForeignPlatformPath(p, adapter.target) && !adapter.excludesSourcePath(p))
.flatMap(sourceRelativePath => {
if (
module.id === 'hooks-runtime'
diff --git a/scripts/lib/install-targets/codex-home.js b/scripts/lib/install-targets/codex-home.js
index 1556a3b3e..aff32c4c5 100644
--- a/scripts/lib/install-targets/codex-home.js
+++ b/scripts/lib/install-targets/codex-home.js
@@ -7,7 +7,5 @@ module.exports = createInstallTargetAdapter({
rootSegments: ['.codex'],
installStatePathSegments: ['ecc-install-state.json'],
nativeRootRelativePath: '.codex',
-
excludedSourcePaths: HOME_INSTALL_EXCLUDED_SOURCE_PATHS,
-
});
diff --git a/scripts/lib/install-targets/helpers.js b/scripts/lib/install-targets/helpers.js
index 38b8038a7..5df5ae1c4 100644
--- a/scripts/lib/install-targets/helpers.js
+++ b/scripts/lib/install-targets/helpers.js
@@ -314,19 +314,6 @@ function createFlatRuleOperations(options) {
}
function createInstallTargetAdapter(config) {
- function supportsSourcePath(sourceRelativePath) {
- const normalizedSourcePath = normalizeRelativePath(sourceRelativePath);
- const excludedSourcePaths = Array.isArray(config.excludedSourcePaths)
- ? config.excludedSourcePaths.map(normalizeRelativePath)
- : [];
-
- return !isForeignPlatformPath(normalizedSourcePath, config.target)
- && !excludedSourcePaths.some(excludedPath => (
- normalizedSourcePath === excludedPath
- || normalizedSourcePath.startsWith(`${excludedPath}/`)
- ));
- }
-
const adapter = {
id: config.id,
target: config.target,
@@ -380,13 +367,9 @@ function createInstallTargetAdapter(config) {
strategy: adapter.determineStrategy(normalizedSourcePath),
});
},
-
- supportsSourcePath,
-
excludesSourcePath(sourceRelativePath) {
return isExcludedSourcePath(sourceRelativePath, config.excludedSourcePaths);
},
-
planOperations(input = {}) {
if (typeof config.planOperations === 'function') {
return config.planOperations(input, adapter);
@@ -396,9 +379,7 @@ function createInstallTargetAdapter(config) {
return input.modules.flatMap(module => {
const paths = Array.isArray(module.paths) ? module.paths : [];
return paths
-
.filter(p => !isForeignPlatformPath(p, config.target) && !adapter.excludesSourcePath(p))
-
.map(sourceRelativePath => adapter.createScaffoldOperation(
module.id,
sourceRelativePath,
@@ -410,9 +391,7 @@ function createInstallTargetAdapter(config) {
const module = input.module || {};
const paths = Array.isArray(module.paths) ? module.paths : [];
return paths
-
.filter(p => !isForeignPlatformPath(p, config.target) && !adapter.excludesSourcePath(p))
-
.map(sourceRelativePath => adapter.createScaffoldOperation(
module.id,
sourceRelativePath,
diff --git a/scripts/lib/install/apply.js b/scripts/lib/install/apply.js
index 10c63e987..209e53784 100644
--- a/scripts/lib/install/apply.js
+++ b/scripts/lib/install/apply.js
@@ -31,10 +31,6 @@ const {
} = require('./claude-settings');
const { filterMcpConfig, parseDisabledMcpServers } = require('../mcp-config');
const { assertWithinTrustedRoot } = require('../path-safety');
-const {
- prepareLegacyAgentsMigration,
- removeLegacyAgentsFiles,
-} = require('./legacy-agents-migration');
const {
assertSafeClaudeSkillOperation,
prepareClaudeSkillMigration,
@@ -694,10 +690,7 @@ function previewInstallPlan(plan) {
assertOpenCodeHookDeactivationReady(plan);
const migration = prepareHookConsentMigration(
plan,
- prepareUserOwnedFileGuard(
- plan,
- prepareLegacyAgentsMigration(plan, prepareClaudeSkillMigration(plan))
- )
+ prepareUserOwnedFileGuard(plan, prepareClaudeSkillMigration(plan))
);
const appliedPlan = {
...plan,
@@ -763,9 +756,7 @@ function applyInstallPlanLocked(plan, dependencies = {}, settingsLockHeld = fals
plan,
prepareHookConsentMigration(
plan,
- prepareUserOwnedFileGuard(
- plan, prepareLegacyAgentsMigration(plan, prepareClaudeSkillMigration(plan))
- )
+ prepareUserOwnedFileGuard(plan, prepareClaudeSkillMigration(plan))
)
);
const appliedPlan = {
@@ -919,7 +910,6 @@ function applyInstallPlanLocked(plan, dependencies = {}, settingsLockHeld = fals
if (hasLegacyMigration) {
removeLegacyClaudeSkillFiles(migration, plan.targetRoot);
}
- removeLegacyAgentsFiles(migration, plan.targetRoot);
if (shouldSetClaudeCommitAttributionPreference(appliedPlan)) {
writeClaudeCommitAttributionPreference(
diff --git a/scripts/lib/install/legacy-agents-migration.js b/scripts/lib/install/legacy-agents-migration.js
deleted file mode 100644
index aac983c54..000000000
--- a/scripts/lib/install/legacy-agents-migration.js
+++ /dev/null
@@ -1,182 +0,0 @@
-'use strict';
-
-const crypto = require('crypto');
-const fs = require('fs');
-const path = require('path');
-
-const { readInstallState } = require('../install-state');
-const { assertWithinTrustedRoot } = require('../path-safety');
-
-const HOME_TARGET_IDS = new Set(['claude-home', 'codex-home']);
-
-function comparablePath(filePath) {
- const resolvedPath = path.resolve(filePath);
- return process.platform === 'win32' ? resolvedPath.toLowerCase() : resolvedPath;
-}
-
-function normalizeRelativePath(relativePath) {
- return String(relativePath || '').replace(/\\/g, '/');
-}
-
-function isLegacyAgentsOperation(plan, operation) {
- if (
- !operation
- || operation.kind !== 'copy-file'
- || operation.ownership !== 'managed'
- || typeof operation.destinationPath !== 'string'
- ) {
- return false;
- }
-
- const sourceRelativePath = normalizeRelativePath(operation.sourceRelativePath);
- if (!sourceRelativePath.startsWith('.agents/')
- || sourceRelativePath.split('/').some(segment => !segment || segment === '.' || segment === '..')) {
- return false;
- }
-
- const expectedDestination = path.join(
- plan.targetRoot,
- ...sourceRelativePath.split('/')
- );
- return comparablePath(operation.destinationPath) === comparablePath(expectedDestination);
-}
-
-function inspectLegacyAgentsOperation(plan, operation) {
- try {
- assertWithinTrustedRoot(
- operation.destinationPath, plan.targetRoot, 'inspect legacy managed .agents file'
- );
- } catch (error) {
- return { removable: false, warning: `Preserved unsafe legacy .agents path ${operation.destinationPath}: ${error.message}` };
- }
-
- let stat;
- try {
- stat = fs.lstatSync(operation.destinationPath);
- } catch (error) {
- if (error && error.code === 'ENOENT') {
- return { removable: false, warning: null };
- }
- throw error;
- }
-
- if (!stat.isFile() || stat.isSymbolicLink()) {
- return {
- removable: false,
- warning: `Preserved legacy .agents path ${operation.destinationPath}: it is not a regular file.`,
- };
- }
-
- if (!/^[a-f0-9]{64}$/i.test(operation.contentSha256 || '')) {
- return {
- removable: false,
- warning: `Preserved legacy .agents file ${operation.destinationPath}: install-state has no verified content digest.`,
- };
- }
-
- const contentSha256 = crypto.createHash('sha256')
- .update(fs.readFileSync(operation.destinationPath))
- .digest('hex');
- if (contentSha256 !== operation.contentSha256.toLowerCase()) {
- return {
- removable: false,
- warning: `Preserved modified legacy .agents file ${operation.destinationPath} and released it from ECC management.`,
- };
- }
-
- return { removable: true, warning: null };
-}
-
-function prepareLegacyAgentsMigration(plan, migration) {
- if (!HOME_TARGET_IDS.has(plan && plan.adapter && plan.adapter.id)) {
- return {
- ...migration,
- legacyAgentsOperationsToDetach: [],
- legacyAgentsOperationsToRemove: [],
- };
- }
-
- const previousState = fs.existsSync(plan.installStatePath)
- ? readInstallState(plan.installStatePath)
- : null;
- const legacyOperations = ((previousState && previousState.operations) || [])
- .filter(operation => isLegacyAgentsOperation(plan, operation));
- if (legacyOperations.length === 0) {
- return {
- ...migration,
- legacyAgentsOperationsToDetach: [],
- legacyAgentsOperationsToRemove: [],
- };
- }
-
- const inspections = legacyOperations.map(operation => ({
- operation,
- ...inspectLegacyAgentsOperation(plan, operation),
- }));
- const legacyDestinations = new Set(
- legacyOperations.map(operation => comparablePath(operation.destinationPath))
- );
- const withoutLegacyAgents = state => ({
- ...state,
- operations: (state.operations || []).filter(operation => (
- !legacyDestinations.has(comparablePath(operation.destinationPath))
- )),
- });
-
- return {
- ...migration,
- finalState: withoutLegacyAgents(migration.finalState),
- legacyAgentsOperationsToDetach: legacyOperations,
- legacyAgentsOperationsToRemove: inspections
- .filter(inspection => inspection.removable)
- .map(inspection => inspection.operation),
- requiresBridgeState: true,
- warnings: [
- ...(migration.warnings || []),
- ...inspections.map(inspection => inspection.warning).filter(Boolean),
- ],
- };
-}
-
-function cleanupEmptyAgentsParents(filePath, targetRoot) {
- const agentsRoot = path.join(targetRoot, '.agents');
- let currentPath = path.dirname(filePath);
-
- while (comparablePath(currentPath) !== comparablePath(targetRoot)) {
- assertWithinTrustedRoot(currentPath, targetRoot, 'clean legacy managed .agents directory');
- if (!fs.existsSync(currentPath) || fs.readdirSync(currentPath).length > 0) {
- return;
- }
- fs.rmdirSync(currentPath);
- if (comparablePath(currentPath) === comparablePath(agentsRoot)) {
- return;
- }
- currentPath = path.dirname(currentPath);
- }
-}
-
-function removeLegacyAgentsFiles(migration, targetRoot) {
- // Load lazily: lifecycle also uses this migration during repair.
- const { removeContainedPath } = require('../install-lifecycle');
- return (migration.legacyAgentsOperationsToRemove || []).flatMap(operation => {
- const latestInspection = inspectLegacyAgentsOperation({ targetRoot }, operation);
- if (!latestInspection.removable) return [];
- const removedPath = removeContainedPath(
- operation.destinationPath, targetRoot, 'remove legacy managed .agents file',
- { force: true, verifyQuarantined: quarantinedPath => {
- const stat = fs.lstatSync(quarantinedPath);
- return stat.isFile() && !stat.isSymbolicLink()
- && crypto.createHash('sha256').update(fs.readFileSync(quarantinedPath)).digest('hex')
- === operation.contentSha256.toLowerCase();
- } }
- );
- if (!removedPath) return [];
- cleanupEmptyAgentsParents(removedPath, targetRoot);
- return [removedPath];
- });
-}
-
-module.exports = {
- prepareLegacyAgentsMigration,
- removeLegacyAgentsFiles,
-};
diff --git a/scripts/sync-ecc-to-codex.sh b/scripts/sync-ecc-to-codex.sh
index 610a65a44..60e75d472 100755
--- a/scripts/sync-ecc-to-codex.sh
+++ b/scripts/sync-ecc-to-codex.sh
@@ -339,7 +339,7 @@ for agent_file in "$CODEX_AGENTS_SRC"/*.toml; do
done
# Skills are NOT synced here — Codex CLI reads directly from
-# ~/.agents/skills/ (Codex's user-level skill discovery path).
+# ~/.agents/skills/ (installed by ECC installer / npx skills).
# Copying into ~/.codex/skills/ was unnecessary.
log "Generating prompt files from ECC commands"
diff --git a/tests/hooks/stop-hooks-stdout.test.js b/tests/hooks/stop-hooks-stdout.test.js
index e3e30d69d..32337754f 100644
--- a/tests/hooks/stop-hooks-stdout.test.js
+++ b/tests/hooks/stop-hooks-stdout.test.js
@@ -26,7 +26,7 @@ const hooksConfig = readHooksConfig(path.join(repoRoot, 'hooks', 'hooks.json'));
const MAX_STDIN = 1024 * 1024;
const SUBPROCESS_TIMEOUT_MS = process.platform === 'darwin' && process.env.CI === 'true'
- ? 180_000
+ ? 120_000
: 60_000;
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-stop-stdout-')); // non-git cwd
diff --git a/tests/lib/legacy-agents-migration.test.js b/tests/lib/legacy-agents-migration.test.js
deleted file mode 100644
index 41ed1e5c9..000000000
--- a/tests/lib/legacy-agents-migration.test.js
+++ /dev/null
@@ -1,98 +0,0 @@
-'use strict';
-const assert = require('assert');
-const crypto = require('crypto');
-const fs = require('fs');
-const os = require('os');
-const path = require('path');
-const { test } = require('node:test');
-const { createInstallState } = require('../../scripts/lib/install-state');
-const { prepareLegacyAgentsMigration, removeLegacyAgentsFiles } = require('../../scripts/lib/install/legacy-agents-migration');
-function fixture(fn) {
- const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-agents-migration-')));
- try { fn(root); } finally { fs.rmSync(root, { recursive: true, force: true }); }
-}
-function prepare(root, source = '.agents/skills/demo.md', destination = path.join(root, source)) {
- const operation = { moduleId: 'legacy', strategy: 'preserve-relative-path', scaffoldOnly: false, kind: 'copy-file', ownership: 'managed', sourceRelativePath: source,
- destinationPath: destination, contentSha256: crypto.createHash('sha256').update('managed').digest('hex') };
- const statePath = path.join(root, 'state.json');
- fs.writeFileSync(statePath, JSON.stringify(createInstallState({ adapter: { id: 'codex-home' }, targetRoot: root, installStatePath: statePath, operations: [operation], request: {}, resolution: {}, source: { manifestVersion: 1 } })));
- return prepareLegacyAgentsMigration({ adapter: { id: 'codex-home' }, targetRoot: root,
- installStatePath: statePath }, { finalState: { operations: [operation] }, warnings: [] });
-}
-function write(file, content = 'managed') { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content); }
-test('removes verified legacy files and returns actual removed paths', () => fixture(root => {
- const file = path.join(root, '.agents/skills/demo.md'); write(file);
- assert.deepStrictEqual(removeLegacyAgentsFiles(prepare(root), root), [file]);
- assert.ok(!fs.existsSync(file));
-}));
-test('rejects dot and parent traversal without detaching unrelated files', () => fixture(root => {
- for (const source of ['.agents/../settings.json', '.agents/./demo.md', '.agents/skills/../../settings.json']) {
- const file = path.join(root, source); write(file);
- const migration = prepare(root, source);
- assert.strictEqual(migration.legacyAgentsOperationsToDetach.length, 0);
- removeLegacyAgentsFiles(migration, root); assert.ok(fs.existsSync(file));
- }
-}));
-test('unsafe ancestor produces warning and preserves outside content', () => fixture(root => {
- const outside = path.join(root, 'outside'); write(path.join(outside, 'demo.md'));
- const home = path.join(root, 'home'); fs.mkdirSync(home);
- fs.symlinkSync(outside, path.join(home, '.agents'), 'dir');
- const migration = prepare(home, '.agents/demo.md');
- assert.strictEqual(migration.legacyAgentsOperationsToRemove.length, 0);
- assert.ok(migration.warnings.length); assert.ok(fs.existsSync(path.join(outside, 'demo.md')));
-}));
-test('preserves content changed after preparation', () => fixture(root => {
- const file = path.join(root, '.agents/skills/demo.md'); write(file);
- const migration = prepare(root); fs.writeFileSync(file, 'changed');
- assert.deepStrictEqual(removeLegacyAgentsFiles(migration, root), []);
- assert.strictEqual(fs.readFileSync(file, 'utf8'), 'changed');
-}));
-test('quarantine identity check preserves replacement during ancestor swap', () => fixture(root => {
- const file = path.join(root, '.agents/skills/demo.md'); write(file);
- const migration = prepare(root); const outside = path.join(root, 'outside'); write(path.join(outside, 'demo.md'), 'user');
- const rename = fs.renameSync; let swapped = false;
- fs.renameSync = (source, destination) => {
- if (source === file && !swapped) {
- swapped = true; rename(path.dirname(file), path.join(root, 'saved-skills'));
- fs.symlinkSync(outside, path.dirname(file), 'dir');
- }
- return rename(source, destination);
- };
- try { assert.throws(() => removeLegacyAgentsFiles(migration, root), /changed/); }
- finally { fs.renameSync = rename; }
- assert.strictEqual(fs.readFileSync(path.join(outside, 'demo.md'), 'utf8'), 'user');
-}));
-test('ignores non-home migrations and empty legacy state', () => fixture(root => {
- const migration = { finalState: { operations: [] }, warnings: [] };
- const result = prepareLegacyAgentsMigration({ adapter: { id: 'cursor-project' } }, migration);
- assert.deepStrictEqual(removeLegacyAgentsFiles(result, root), []);
- const empty = prepareLegacyAgentsMigration({ adapter: { id: 'codex-home' },
- targetRoot: root, installStatePath: path.join(root, 'missing.json') }, migration);
- assert.deepStrictEqual(empty.legacyAgentsOperationsToDetach, []);
-}));
-test('preserves missing, symbolic, modified and unverifiable legacy files', () => fixture(root => {
- const file = path.join(root, '.agents/skills/demo.md');
- assert.strictEqual(prepare(root).legacyAgentsOperationsToRemove.length, 0);
- write(file, 'changed'); assert.ok(prepare(root).warnings.length);
- fs.unlinkSync(file); write(path.join(root, 'user.md'));
- fs.symlinkSync(path.join(root, 'user.md'), file);
- assert.ok(prepare(root).warnings.length); fs.unlinkSync(file); write(file);
- prepare(root);
- const statePath = path.join(root, 'state.json');
- const state = JSON.parse(fs.readFileSync(statePath, 'utf8'));
- delete state.operations[0].contentSha256; fs.writeFileSync(statePath, JSON.stringify(state));
- const migration = prepareLegacyAgentsMigration({ adapter: { id: 'codex-home' }, targetRoot: root,
- installStatePath: statePath }, { finalState: state, warnings: [] });
- assert.ok(migration.warnings[0].includes('no verified content digest'));
-}));
-test('digest revalidation preserves same-inode content changed during quarantine', () => fixture(root => {
- const file = path.join(root, '.agents/skills/demo.md'); write(file);
- const migration = prepare(root); const rename = fs.renameSync; let changed = false;
- fs.renameSync = (source, destination) => {
- if (source === file && !changed) { changed = true; fs.writeFileSync(source, 'changed during rename'); }
- return rename(source, destination);
- };
- try { assert.throws(() => removeLegacyAgentsFiles(migration, root), /changed/); }
- finally { fs.renameSync = rename; }
- assert.strictEqual(fs.readFileSync(file, 'utf8'), 'changed during rename');
-}));