From 31ecd4b1c3459c6f1ff9e4e002fec064f33d7ac0 Mon Sep 17 00:00:00 2001 From: MohamedAfrash Date: Tue, 13 Oct 2026 16:23:24 +0100 Subject: [PATCH] fix: honor Antigravity runtime policy and contain managed installs GREEN: hook policy 4/4, MCP policy 8/8, native Antigravity 1.2.9 import, tier suite 24/24, lifecycle 5/5 plus 73 existing checks. Use shared enable/profile/dry-run decisions and managed setup; stop importing source MCP definitions and filter mcp_config.json. Derive sibling workflow roots for doctor/repair/uninstall and refuse escapes. Restore upstream Claude setup behavior after four migration regressions. Update module targets, carrier schema, unchanged trigger binding, and native validation limits. --- README.md | 2 +- docs/ANTIGRAVITY-GUIDE.md | 52 +++++++++++++- manifests/context-packs/skill-triggers@1.json | 2 +- manifests/install-modules.json | 5 ++ schemas/context-carrier.schema.json | 2 +- scripts/hooks/antigravity-hook-bridge.js | 7 ++ scripts/lib/antigravity-hooks.js | 8 +-- scripts/lib/claude-plugin-setup.js | 20 ++---- scripts/lib/install-lifecycle.js | 3 +- .../lib/install-targets/antigravity-home.js | 50 ++++++-------- .../install-targets/antigravity-project.js | 40 ++++------- scripts/lib/install/apply.js | 2 +- scripts/plan-canvas.js | 1 - tests/lib/antigravity-lifecycle.test.js | 67 +++++++++++++------ tests/lib/antigravity-tier1.test.js | 1 + tests/lib/claude-plugin-setup.test.js | 17 ----- tests/scripts/antigravity-hook-bridge.test.js | 1 + .../scripts/antigravity-native-plugin.test.js | 16 +++-- tests/scripts/codex-hooks.test.js | 1 - 19 files changed, 169 insertions(+), 128 deletions(-) diff --git a/README.md b/README.md index bd9f1f22b..3f0c9e2a6 100644 --- a/README.md +++ b/README.md @@ -1325,7 +1325,7 @@ Treat `stable`, `beta`, `experimental`, and `instruction-only` below as capabili |---|---|---|---| | Claude Code | Stable primary | Plugin or selective installer | The plugin advertises the installed catalog to the model; use a selective/manual profile when context footprint matters. Optional shell-backed skills are not portable to every OS. | | Codex | Supported native plugin | Codex marketplace plugin or repo config | Native hooks require an explicit trust decision and do not use Claude's hook profiles. The legacy sync is compatibility-only. | -| Antigravity | Supported native plugin | Native plugin (`~/.gemini/config/plugins/ecc`) or project `.agents/` | Global native plugin with lifecycle hooks (`PreToolUse`, `PostToolUse`, `Stop`) via protojson bridge, rules, workflows, skills, and memory MCP. | +| Antigravity | Native plugin adapter | Antigravity 2.0/IDE plugin (`~/.gemini/config/plugins/ecc`) or project `.agents/` | Profile-gated lifecycle hooks, rules, workflows, skills, and memory MCP. CLI 1.2.9 validates local import; authenticated native tool and Stop execution remain unverified. | | Qoder | Supported native plugin | Local plugin directory in Qoder CLI or ZIP upload in Qoder IDE | Loads the canonical skills, agents, commands, and MCP config; only the reviewed SessionStart hook is enabled, and Node.js 18+ must be on the non-interactive PATH. | | Cursor | Beta project adapter | Selective installer into `.cursor/` | Agent discovery varies by Cursor build; hook events use profile-gated dispatchers, but full Claude feature parity is not claimed. | | OpenCode | Beta built plugin | Build plugin, then selective installer | ECC ships a subset of the catalog; connect a provider and select a model in OpenCode ([#2617](https://github.com/affaan-m/ECC/issues/2617)). | diff --git a/docs/ANTIGRAVITY-GUIDE.md b/docs/ANTIGRAVITY-GUIDE.md index b498492e7..0ca21be6a 100644 --- a/docs/ANTIGRAVITY-GUIDE.md +++ b/docs/ANTIGRAVITY-GUIDE.md @@ -150,12 +150,12 @@ node "$EccRoot\scripts\uninstall.js" --target antigravity --dry-run - Confirm the files are under `.agents/workflows/`. - Invoke a workflow with `/` after restarting Antigravity. -## Tier 1 Native Plugin and Global Installation (`antigravity-home`) +## Native Plugin and Global Installation (`antigravity-home`) Antigravity supports global plugins located in `~/.gemini/config/plugins//`. Installing ECC as a native Antigravity plugin enables: 1. **Global Scope**: ECC rules, skills, agents, workflows, and memory MCP are active across all projects automatically, without requiring a `.agents/` folder in every repository. -2. **Lifecycle Hooks (`hooks.json`)**: Full support for `PreToolUse` (command security gates, file modification guards), `PostToolUse` edit tracking, and `Stop` formatting and diagnostics using Antigravity's protojson protocol (`{ decision, reason }`). +2. **Lifecycle Hooks (`hooks.json`)**: Handlers for `PreToolUse` command and file guards, `PostToolUse` edit tracking, and `Stop` formatting and diagnostics using Antigravity's protojson protocol (`{ decision, reason }`). 3. **Shared Memory Vault (`mcp_config.json`)**: Direct integration with `ecc-memory-mcp` across all Antigravity sessions. 4. **Native Plugin Manifest (`plugin.json`)**: Declares the ECC plugin metadata. @@ -173,11 +173,23 @@ PowerShell: ``` The installer copies the memory server and its runtime dependencies into the -managed target. Generated hook and MCP commands use absolute installed paths, +managed target. Only ECC memory is included in the generated MCP configuration; +repository `.mcp.json` commands are not imported automatically. Set +`ECC_DISABLED_MCPS=ecc-memory` during installation to omit that server. +Existing MCP entries are preserved on upgrades, including servers generated by +older ECC versions. Review `mcp_config.json` and remove any unwanted existing +entries explicitly; installation does not delete user configuration. +Generated hook and MCP commands use absolute installed paths, so they also work when Antigravity runs from another workspace. Project-local hooks use the same runtime; select `--profile core --enable-hooks` with `--target antigravity`. Use `--no-hooks` to omit automatic hooks. +Choose a hook profile at installation with the existing environment setting, for +example `ECC_HOOK_PROFILE=minimal "$ECC_ROOT/install.sh" --target antigravity-home --profile core --enable-hooks`. +The installer retains it in managed `ecc/setup.json` for runtime execution. +`ECC_HOOK_PROFILE` overrides that profile; `ECC_DISABLED_HOOKS` disables individual +hook IDs, and `ECC_DRY_RUN=1` suppresses hook execution. These controls also apply +to the Antigravity bridge. ### Global Plugin Structure @@ -188,12 +200,46 @@ with `--target antigravity`. Use `--no-hooks` to omit automatic hooks. ├── plugin.json # Antigravity plugin manifest ├── hooks.json # PreToolUse, PostToolUse, and Stop hooks ├── mcp_config.json # Shared ECC Memory Vault MCP server + ├── ecc/setup.json # Managed hook enable/profile configuration ├── rules/ # Rules applied to all workspaces ├── skills/ # Global Agent Skills ├── scripts/ # Hook bridge and memory runtime └── node_modules/ # Memory server dependencies ``` +### Native validation and limits + +Run the optional native check from the ECC source checkout: + +```bash +node tests/scripts/antigravity-native-plugin.test.js +``` + +The test requires an already installed **Antigravity CLI 1.2.9** and skips with an +explicit message if that version is unavailable. It does not download the CLI. +It installs ECC into one temporary home, runs `agy plugin validate`, imports the +local plugin into a separate disposable CLI home with `agy plugin install`, and +checks `agy plugin list --json`. +Every CLI subprocess uses disposable home and configuration directories without +inheriting authentication credentials. The test makes no model requests. + +This validates the CLI's local plugin importer and component registration. +CLI 1.2.9 does not list a manually placed `~/.gemini/config/plugins/ecc` plugin +until explicitly imported; its CLI staging location differs from the Antigravity +2.0 and IDE global location. Importing directly from the same home plugin directory +fails in CLI 1.2.9 because its importer attempts to copy onto the source directory. +The test uses separate install and loader homes to exercise the importer without +that collision; this does not establish in-place CLI activation of the home target. + +The CLI exposes no standalone tool-event or Stop-event runner. The existing +bridge tests check allowed and denied tool payloads and Stop behavior directly; +they do **not** establish native loader execution. Automatic IDE discovery, +allowed and denied tool execution, and Stop execution still require a real +Antigravity session. In Settings > Customizations, verify ECC appears, then use +a disposable workspace to verify an ordinary command proceeds, a destructive +command is denied before execution, and an edit triggers the expected Stop +formatting or diagnostics. Never use valuable files for the denial check. + ## Official Antigravity references - [Skills](https://antigravity.google/docs/skills) diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index a49a8c824..5d980781e 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "498caee2738006d64530e9be34883111cf67742d8c4389f39d61299e1a1c4400", + "registryDigest": "25fdb7f75a02286ffddaa5902c0803be09d7e5a9a55797bb9f0224816e3d18e7", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/manifests/install-modules.json b/manifests/install-modules.json index bf6e9f38b..a26e24358 100644 --- a/manifests/install-modules.json +++ b/manifests/install-modules.json @@ -372,6 +372,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -453,6 +454,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "copilot", "opencode", @@ -1397,6 +1399,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -1428,6 +1431,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -1461,6 +1465,7 @@ "cursor", "copilot", "antigravity", + "antigravity-home", "opencode", "codebuddy", "joycode", diff --git a/schemas/context-carrier.schema.json b/schemas/context-carrier.schema.json index 03a48ce67..87905bf48 100644 --- a/schemas/context-carrier.schema.json +++ b/schemas/context-carrier.schema.json @@ -10,7 +10,7 @@ "active": { "const": false }, "disposition": { "const": "proposed" }, "nativeSupport": { "const": "unobserved" }, - "target": { "enum": ["adal", "antigravity", "claude", "claude-project", "codebuddy", "codex", "copilot", "cursor", "gemini", "hermes", "joycode", "kimi", "openclaw", "opencode", "pi", "qwen", "zed"] }, + "target": { "enum": ["adal", "antigravity", "antigravity-home", "claude", "claude-project", "codebuddy", "codex", "copilot", "cursor", "gemini", "hermes", "joycode", "kimi", "openclaw", "opencode", "pi", "qwen", "zed"] }, "profileId": { "enum": ["lean@1", "full@1"] }, "selectionMode": { "enum": ["manual", "suggest", "auto"] }, "registryDigest": { "$ref": "#/definitions/digest" }, diff --git a/scripts/hooks/antigravity-hook-bridge.js b/scripts/hooks/antigravity-hook-bridge.js index 177a0ae0f..5d2699298 100644 --- a/scripts/hooks/antigravity-hook-bridge.js +++ b/scripts/hooks/antigravity-hook-bridge.js @@ -16,6 +16,7 @@ const { run: runGateGuard } = require('./gateguard-fact-force'); const { run: runDocFileWarning } = require('./doc-file-warning'); const { run: runPostEditAccumulator } = require('./post-edit-accumulator'); const { readStdinRaw, resolveMaxStdin } = require('./hook-input'); +const { isHookEnabled, isDryRun } = require('../lib/hook-flags'); function parseArgs(argv) { const options = { @@ -71,6 +72,12 @@ function writeFailure(mode, reason) { async function main() { const options = parseArgs(process.argv); + process.env.ECC_HOOK_CONFIG ||= path.resolve(__dirname, '../../ecc/setup.json'); + const profiles = options.hook === 'pre:bash:dispatcher' ? 'minimal,standard,strict' : undefined; + if (!isHookEnabled(options.hook, { profiles }) || isDryRun()) { + process.stdout.write(JSON.stringify(options.mode === 'post-tool-use' ? {} : { decision: 'allow' })); + return; + } const maxStdin = resolveMaxStdin(process.env.ECC_HOOK_INPUT_MAX_BYTES); let raw = ''; diff --git a/scripts/lib/antigravity-hooks.js b/scripts/lib/antigravity-hooks.js index cc496665c..d5977fea7 100644 --- a/scripts/lib/antigravity-hooks.js +++ b/scripts/lib/antigravity-hooks.js @@ -12,7 +12,6 @@ const { shellQuote } = require('./control-pane/actions'); */ function buildAntigravityHooksConfig(options = {}) { - const profile = options.profile || 'standard'; const { bridgeScript } = options; if (typeof bridgeScript !== 'string' || !path.isAbsolute(bridgeScript) || bridgeScript.includes('\0')) { throw new Error('bridgeScript must be an absolute path'); @@ -55,8 +54,8 @@ function buildAntigravityHooksConfig(options = {}) { }, ]; - if (profile === 'standard' || profile === 'strict') { - preToolUseHandlers.push({ + // Runtime hook flags select the profile, including explicit environment overrides. + preToolUseHandlers.push({ matcher: 'write_to_file', hooks: [ { @@ -65,8 +64,7 @@ function buildAntigravityHooksConfig(options = {}) { timeout: 5, }, ], - }); - } + }); const stopHandlers = [ { diff --git a/scripts/lib/claude-plugin-setup.js b/scripts/lib/claude-plugin-setup.js index bde0f3ff6..97f5969b2 100644 --- a/scripts/lib/claude-plugin-setup.js +++ b/scripts/lib/claude-plugin-setup.js @@ -572,7 +572,6 @@ function verifyPluginAtScope(options) { function ensurePluginAtScope(options) { const run = options.run || runClaude; - const configuredHooks = options.hookConfiguration; if (options.installed) { run( ['plugin', 'update', CURRENT_PLUGIN_ID, '--scope', options.scope], @@ -580,17 +579,13 @@ function ensurePluginAtScope(options) { ); return 'updated'; } - const installArgs = [ - 'plugin', 'install', CURRENT_PLUGIN_ID, - '--scope', options.scope, - ]; - if (configuredHooks) { - installArgs.push( - '--config', `hooks_enabled=${configuredHooks.hooks_enabled}`, - '--config', `hook_profile=${configuredHooks.hook_profile}` - ); - } - run(installArgs, { cwd: options.projectRoot, phase: 'plugin-install' }); + run( + [ + 'plugin', 'install', CURRENT_PLUGIN_ID, + '--scope', options.scope, + ], + { cwd: options.projectRoot, phase: 'plugin-install' } + ); return 'installed'; } @@ -660,7 +655,6 @@ function setupClaudePlugin(options = {}, dependencies = {}) { spawnSync: dependencies.spawnSync, }); const action = ensurePluginAtScope({ - hookConfiguration: hookOptions(hooks), hooks, installed: inventory.installed, projectRoot: paths.projectRoot, diff --git a/scripts/lib/install-lifecycle.js b/scripts/lib/install-lifecycle.js index f4fba36b7..76805cfc6 100644 --- a/scripts/lib/install-lifecycle.js +++ b/scripts/lib/install-lifecycle.js @@ -874,7 +874,8 @@ function inspectManagedOperation(repoRoot, trustedRoot, operation, linkIndex = n } function trustedRootForDestination(destinationPath, targetRoot, trustedRoots = [targetRoot]) { - return trustedRoots.find(root => isWithinRoot(destinationPath, root)) || targetRoot; + const parent = typeof destinationPath === 'string' ? path.dirname(destinationPath) : destinationPath; + return trustedRoots.find(root => isWithinRoot(parent, root)) || targetRoot; } function summarizeManagedOperationHealth(repoRoot, trustedRoot, operations, target = null, trustedRoots = [trustedRoot]) { diff --git a/scripts/lib/install-targets/antigravity-home.js b/scripts/lib/install-targets/antigravity-home.js index 2be18d0d9..c3a53372a 100644 --- a/scripts/lib/install-targets/antigravity-home.js +++ b/scripts/lib/install-targets/antigravity-home.js @@ -15,21 +15,8 @@ const { const { buildAntigravityHooksConfig } = require('../antigravity-hooks'); const { buildAntigravityMcpConfig, planAntigravityMemoryRuntime } = require('../antigravity-mcp'); const { buildAntigravityPluginManifest } = require('../antigravity-plugin'); - -function readJsonObject(filePath, label) { - let parsed; - try { - parsed = JSON.parse(fs.readFileSync(filePath, 'utf8')); - } catch (error) { - throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`); - } - - if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) { - throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`); - } - - return parsed; -} +const { getHookProfile } = require('../hook-flags'); +const { isWithinRoot } = require('../path-safety'); module.exports = createInstallTargetAdapter({ id: 'antigravity-home', @@ -40,10 +27,11 @@ module.exports = createInstallTargetAdapter({ nativeRootRelativePath: '.gemini', excludedSourcePaths: HOME_INSTALL_EXCLUDED_SOURCE_PATHS, resolveTrustedRoots(input, targetRoot) { - const workflowsRoot = path.join( - path.dirname(path.dirname(targetRoot)), - 'workflows' - ); + const configRoot = path.dirname(path.dirname(targetRoot)); + const workflowsRoot = path.join(configRoot, 'workflows'); + if (!isWithinRoot(workflowsRoot, configRoot)) { + throw new Error('Refusing Antigravity workflows outside the trusted config root.'); + } return [targetRoot, workflowsRoot]; }, planOperations(input, adapter) { @@ -141,6 +129,7 @@ module.exports = createInstallTargetAdapter({ module.id === 'hooks-runtime' && normalizedSourcePath === 'hooks' ) { + const profile = getHookProfile(input.env); return [ createManagedScaffoldOperation(module.id, 'package.json', path.join(targetRoot, 'package.json'), 'preserve-relative-path'), createManagedOperation({ @@ -152,10 +141,20 @@ module.exports = createInstallTargetAdapter({ ownership: 'managed', scaffoldOnly: false, mergePayload: buildAntigravityHooksConfig({ - profile: input.hookProfile || 'standard', + profile, bridgeScript: path.join(targetRoot, 'scripts', 'hooks', 'antigravity-hook-bridge.js'), }), }), + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: 'hooks/hooks.json', + destinationPath: path.join(targetRoot, 'ecc', 'setup.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: { hooks: { enabled: true, profile } }, + }), ]; } @@ -163,18 +162,9 @@ module.exports = createInstallTargetAdapter({ module.id === 'platform-configs' && (normalizedSourcePath === 'mcp-configs' || normalizedSourcePath === '.mcp.json') ) { - const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json'))) - ? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json') - : { mcpServers: {} }; const antigravityMcp = buildAntigravityMcpConfig({ memoryScript: path.join(targetRoot, 'scripts', 'memory-mcp.mjs'), }); - const mergedMcp = { - mcpServers: { - ...(baseMcp.mcpServers || {}), - ...(antigravityMcp.mcpServers || {}), - }, - }; const operations = [ createManagedOperation({ @@ -185,7 +175,7 @@ module.exports = createInstallTargetAdapter({ strategy: 'merge-json', ownership: 'managed', scaffoldOnly: false, - mergePayload: mergedMcp, + mergePayload: antigravityMcp, }), createManagedOperation({ kind: 'merge-json', diff --git a/scripts/lib/install-targets/antigravity-project.js b/scripts/lib/install-targets/antigravity-project.js index 647c4eb7d..375976844 100644 --- a/scripts/lib/install-targets/antigravity-project.js +++ b/scripts/lib/install-targets/antigravity-project.js @@ -11,6 +11,7 @@ const { const { buildAntigravityHooksConfig } = require('../antigravity-hooks'); const { buildAntigravityMcpConfig, planAntigravityMemoryRuntime } = require('../antigravity-mcp'); const { buildAntigravityPluginManifest } = require('../antigravity-plugin'); +const { getHookProfile } = require('../hook-flags'); const SUPPORTED_SOURCE_PREFIXES = [ 'rules', @@ -31,21 +32,6 @@ function supportsAntigravitySourcePath(sourceRelativePath) { )); } -function readJsonObject(filePath, label) { - let parsed; - try { - parsed = JSON.parse(fs.readFileSync(filePath, 'utf8')); - } catch (error) { - throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`); - } - - if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) { - throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`); - } - - return parsed; -} - module.exports = createInstallTargetAdapter({ id: 'antigravity-project', target: 'antigravity', @@ -148,6 +134,7 @@ module.exports = createInstallTargetAdapter({ module.id === 'hooks-runtime' && normalizedSourcePath === 'hooks' ) { + const profile = getHookProfile(input.env); return [ createManagedScaffoldOperation(module.id, 'package.json', path.join(targetRoot, 'package.json'), 'preserve-relative-path'), createManagedOperation({ @@ -159,10 +146,20 @@ module.exports = createInstallTargetAdapter({ ownership: 'managed', scaffoldOnly: false, mergePayload: buildAntigravityHooksConfig({ - profile: input.hookProfile || 'standard', + profile, bridgeScript: path.join(targetRoot, 'scripts', 'hooks', 'antigravity-hook-bridge.js'), }), }), + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: 'hooks/hooks.json', + destinationPath: path.join(targetRoot, 'ecc', 'setup.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: { hooks: { enabled: true, profile } }, + }), ]; } @@ -170,18 +167,9 @@ module.exports = createInstallTargetAdapter({ module.id === 'platform-configs' && (normalizedSourcePath === 'mcp-configs' || normalizedSourcePath === '.mcp.json') ) { - const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json'))) - ? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json') - : { mcpServers: {} }; const antigravityMcp = buildAntigravityMcpConfig({ memoryScript: path.join(targetRoot, 'scripts', 'memory-mcp.mjs'), }); - const mergedMcp = { - mcpServers: { - ...(baseMcp.mcpServers || {}), - ...(antigravityMcp.mcpServers || {}), - }, - }; const operations = [ createManagedOperation({ @@ -192,7 +180,7 @@ module.exports = createInstallTargetAdapter({ strategy: 'merge-json', ownership: 'managed', scaffoldOnly: false, - mergePayload: mergedMcp, + mergePayload: antigravityMcp, }), createManagedOperation({ kind: 'merge-json', diff --git a/scripts/lib/install/apply.js b/scripts/lib/install/apply.js index cec446c98..82fef1ffd 100644 --- a/scripts/lib/install/apply.js +++ b/scripts/lib/install/apply.js @@ -254,7 +254,7 @@ function writeClaudeCommitAttributionPreference(settingsPath, options = {}) { function isMcpConfigPath(filePath) { const basename = path.basename(String(filePath || '')); - return basename === '.mcp.json' || basename === 'mcp.json'; + return basename === '.mcp.json' || basename === 'mcp.json' || basename === 'mcp_config.json'; } function getTrustedRootsForPlan(plan) { diff --git a/scripts/plan-canvas.js b/scripts/plan-canvas.js index 96d075e93..bc8f49d45 100755 --- a/scripts/plan-canvas.js +++ b/scripts/plan-canvas.js @@ -17,7 +17,6 @@ * so stdout stays parseable. */ -const { spawn } = require('child_process'); const fs = require('fs'); const http = require('http'); const path = require('path'); diff --git a/tests/lib/antigravity-lifecycle.test.js b/tests/lib/antigravity-lifecycle.test.js index 84c0692ec..0851c3019 100644 --- a/tests/lib/antigravity-lifecycle.test.js +++ b/tests/lib/antigravity-lifecycle.test.js @@ -8,7 +8,7 @@ const path = require('path'); const { createManifestInstallPlan } = require('../../scripts/lib/install/plan'); const { applyInstallPlan } = require('../../scripts/lib/install/apply'); const { withHookConsent } = require('../../scripts/lib/install/hook-consent'); -const { buildDoctorReport, repairInstalledStates } = require('../../scripts/lib/install-lifecycle'); +const { buildDoctorReport, repairInstalledStates, uninstallInstalledStates } = require('../../scripts/lib/install-lifecycle'); const repoRoot = path.join(__dirname, '..', '..'); const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'antigravity-lifecycle-')); @@ -25,24 +25,7 @@ try { projectRoot, }), 'enabled'); const workflowPath = path.join(homeDir, '.gemini', 'config', 'workflows', 'plan.md'); - const workflowOperation = { - kind: 'copy-file', - moduleId: 'commands-core', - sourcePath: path.join(repoRoot, 'commands', 'plan.md'), - sourceRelativePath: 'commands/plan.md', - destinationPath: workflowPath, - strategy: 'preserve-relative-path', - ownership: 'managed', - scaffoldOnly: false, - }; - applyInstallPlan({ - ...plan, - operations: [...plan.operations, workflowOperation], - statePreview: { - ...plan.statePreview, - operations: [...plan.statePreview.operations, workflowOperation], - }, - }); + applyInstallPlan(plan); const original = fs.readFileSync(workflowPath, 'utf8'); fs.unlinkSync(workflowPath); @@ -77,7 +60,51 @@ try { assert.strictEqual(refused.status, 'error'); assert.match(refused.error, /unsafe managed destination|symlink/i); assert.strictEqual(fs.readFileSync(outsidePath, 'utf8'), 'user content'); - console.log('Results: Passed: 3, Failed: 0'); + + const uninstalled = uninstallInstalledStates({ + homeDir, + projectRoot, + targets: ['antigravity-home'], + }).results[0]; + assert.strictEqual(uninstalled.status, 'partial', uninstalled.error); + assert.ok(uninstalled.retainedPaths.includes(workflowPath)); + assert.ok(fs.lstatSync(workflowPath).isSymbolicLink()); + assert.strictEqual(fs.readFileSync(outsidePath, 'utf8'), 'user content'); + + const symlinkHome = path.join(fixtureRoot, 'symlink-home'); + const symlinkProject = path.join(fixtureRoot, 'symlink-project'); + fs.mkdirSync(symlinkHome); + fs.mkdirSync(symlinkProject); + const symlinkPlan = withHookConsent(createManifestInstallPlan({ + profileId: 'core', + target: 'antigravity-home', + homeDir: symlinkHome, + projectRoot: symlinkProject, + }), 'enabled'); + applyInstallPlan(symlinkPlan); + const workflowsRoot = path.join(symlinkHome, '.gemini', 'config', 'workflows'); + const externalRoot = path.join(fixtureRoot, 'external-workflows'); + fs.renameSync(workflowsRoot, externalRoot); + fs.symlinkSync(externalRoot, workflowsRoot, 'dir'); + const externalWorkflow = path.join(externalRoot, 'plan.md'); + const externalContent = fs.readFileSync(externalWorkflow, 'utf8'); + + assert.throws(() => applyInstallPlan(symlinkPlan), /outside|symlink|trusted/i); + const rootSymlinkRepair = repairInstalledStates({ + repoRoot, + homeDir: symlinkHome, + projectRoot: symlinkProject, + targets: ['antigravity-home'], + }).results[0]; + const rootSymlinkUninstall = uninstallInstalledStates({ + homeDir: symlinkHome, + projectRoot: symlinkProject, + targets: ['antigravity-home'], + }).results[0]; + assert.strictEqual(rootSymlinkRepair.status, 'error'); + assert.strictEqual(rootSymlinkUninstall.status, 'error'); + assert.strictEqual(fs.readFileSync(externalWorkflow, 'utf8'), externalContent); + console.log('Results: Passed: 5, Failed: 0'); } finally { fs.rmSync(fixtureRoot, { recursive: true, force: true }); } diff --git a/tests/lib/antigravity-tier1.test.js b/tests/lib/antigravity-tier1.test.js index 56725d202..1d5ca5034 100644 --- a/tests/lib/antigravity-tier1.test.js +++ b/tests/lib/antigravity-tier1.test.js @@ -380,6 +380,7 @@ function runTests() { const run = spawnSync(process.execPath, [bridgePath, '--mode', 'pre-tool-use', '--hook', 'pre:bash:dispatcher'], { input, encoding: 'utf8', + env: { ...process.env, GATEGUARD_BASH_ROUTINE_DISABLED: '1' }, }); assert.strictEqual(run.status, 0); diff --git a/tests/lib/claude-plugin-setup.test.js b/tests/lib/claude-plugin-setup.test.js index fa752342b..f80014a45 100644 --- a/tests/lib/claude-plugin-setup.test.js +++ b/tests/lib/claude-plugin-setup.test.js @@ -295,8 +295,6 @@ test('fresh install uses supported Claude arguments and follows the verification [ 'plugin', 'install', 'ecc@ecc', '--scope', 'project', - '--config', 'hooks_enabled=true', - '--config', 'hook_profile=strict', ], ['plugin', 'list', '--json'], ]); @@ -327,19 +325,6 @@ test('fresh installs support all Claude scopes while hook preferences stay user- } }); -test('fresh installs pass disabled hooks to the provider before activation', () => { - withFixture({}, fixture => { - setupClaudePlugin(setupOptions(fixture, { scope: 'user', hooks: 'off' })); - const install = readCalls(fixture).find(argv => argv[1] === 'install'); - assert.deepStrictEqual(install, [ - 'plugin', 'install', 'ecc@ecc', '--scope', 'user', - '--config', 'hooks_enabled=false', '--config', 'hook_profile=standard', - ]); - const settings = JSON.parse(fs.readFileSync(fixture.settingsPath, 'utf8')); - assert.strictEqual(settings.pluginConfigs['ecc@ecc'].options.hooks_enabled, false); - }); -}); - test('same-scope repeat setup updates ECC and changes durable user hook preferences', () => { withFixture({ plugins: [installedPlugin('local')], @@ -747,8 +732,6 @@ test('provider failures stop later operations and leave settings untouched', () const installArgv = [ 'plugin', 'install', 'ecc@ecc', '--scope', 'user', - '--config', 'hooks_enabled=true', - '--config', 'hook_profile=standard', ]; withFixture({ failures: [{ diff --git a/tests/scripts/antigravity-hook-bridge.test.js b/tests/scripts/antigravity-hook-bridge.test.js index 2393607ba..2566de33b 100644 --- a/tests/scripts/antigravity-hook-bridge.test.js +++ b/tests/scripts/antigravity-hook-bridge.test.js @@ -23,6 +23,7 @@ async function invoke({ hook = 'pre:edit-write:gateguard-fact-force', mode = 'pr './doc-file-warning': { run }, './post-edit-accumulator': { run }, './stop-format-typecheck': { run }, + '../lib/hook-flags': { isHookEnabled: () => true, isDryRun: () => false }, './hook-input': { resolveMaxStdin: () => 1024, readStdinRaw: async () => { if (readError) throw new Error('read failed'); return { raw, truncated }; }, diff --git a/tests/scripts/antigravity-native-plugin.test.js b/tests/scripts/antigravity-native-plugin.test.js index 26d1706c3..28f069127 100644 --- a/tests/scripts/antigravity-native-plugin.test.js +++ b/tests/scripts/antigravity-native-plugin.test.js @@ -10,15 +10,17 @@ const { applyInstallPlan } = require('../../scripts/lib/install/apply'); const { withHookConsent } = require('../../scripts/lib/install/hook-consent'); const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-agy-native-')); +const loaderHome = path.join(root, 'loader-home'); +fs.mkdirSync(loaderHome); // Only pass filesystem locations owned by this test; never inherit authentication. const env = { PATH: process.env.PATH, - HOME: root, - USERPROFILE: root, - XDG_CONFIG_HOME: path.join(root, '.config'), - XDG_DATA_HOME: path.join(root, '.local', 'share'), - XDG_CACHE_HOME: path.join(root, '.cache'), - ...(process.platform === 'win32' ? { SystemRoot: process.env.SystemRoot, APPDATA: root, LOCALAPPDATA: root } : {}), + HOME: loaderHome, + USERPROFILE: loaderHome, + XDG_CONFIG_HOME: path.join(loaderHome, '.config'), + XDG_DATA_HOME: path.join(loaderHome, '.local', 'share'), + XDG_CACHE_HOME: path.join(loaderHome, '.cache'), + ...(process.platform === 'win32' ? { SystemRoot: process.env.SystemRoot, APPDATA: loaderHome, LOCALAPPDATA: loaderHome } : {}), }; function agy(args) { @@ -42,7 +44,7 @@ try { profileId: 'core', target: 'antigravity-home', projectRoot: path.join(root, 'workspace'), - homeDir: root, + homeDir: path.join(root, 'install-home'), }), 'enabled'); applyInstallPlan(plan); assert.ok(fs.existsSync(path.join(plan.targetRoot, 'plugin.json'))); diff --git a/tests/scripts/codex-hooks.test.js b/tests/scripts/codex-hooks.test.js index fc31f103d..85e2f31af 100644 --- a/tests/scripts/codex-hooks.test.js +++ b/tests/scripts/codex-hooks.test.js @@ -493,7 +493,6 @@ function runHermeticPythonPrePush({ ECC_PREPUSH_RUN_CHECKS: '1', ECC_SKIP_GIT_HOOKS: '0', ECC_SKIP_PREPUSH: '0', - ECC_PREPUSH_RUN_CHECKS: '1', MSYS_NO_PATHCONV: '1', ...(venvDir === null || trackVenv ? {} : { VIRTUAL_ENV: toBashPath(venvDir) }), ...(override === null ? {} : { ECC_PYTEST_CMD: override }),