diff --git a/.config/repo/oxfmtrc.json b/.config/repo/oxfmtrc.json new file mode 100644 index 00000000..e31060f5 --- /dev/null +++ b/.config/repo/oxfmtrc.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxfmt/configuration_schema.json", + "useTabs": false, + "tabWidth": 2, + "printWidth": 80, + "singleQuote": true, + "jsxSingleQuote": false, + "quoteProps": "as-needed", + "trailingComma": "all", + "semi": false, + "arrowParens": "avoid", + "bracketSameLine": false, + "bracketSpacing": true, + "singleAttributePerLine": false, + "jsdoc": { + "addDefaultToDescription": false, + "bracketSpacing": false, + "capitalizeDescriptions": true, + "commentLineStrategy": "multiline", + "descriptionTag": false, + "descriptionWithDot": true, + "keepUnparsableExampleIndent": false, + "lineWrappingStyle": "balance", + "preferCodeFences": false, + "separateReturnsFromParam": false, + "separateTagGroups": true + }, + "ignorePatterns": [ + "**/node_modules/**", + "**/fixtures/**", + "**/wasm_exec.js", + "**/bootstrap/**" + ] +} diff --git a/.config/repo/oxlintrc.json b/.config/repo/oxlintrc.json new file mode 100644 index 00000000..e19fe048 --- /dev/null +++ b/.config/repo/oxlintrc.json @@ -0,0 +1,158 @@ +{ + "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/5306f24d9e82ae36ad9c3c964f33075bc589c799/npm/oxlint/configuration_schema.json", + "plugins": ["typescript", "unicorn", "import"], + "categories": { + "correctness": "error", + "suspicious": "error" + }, + "rules": { + "eslint/complexity": ["error", 15], + "eslint/curly": "error", + "eslint/no-await-in-loop": "off", + "eslint/no-console": "off", + "eslint/no-control-regex": "off", + "eslint/no-empty": [ + "error", + { + "allowEmptyCatch": true + } + ], + "eslint/no-new": "error", + "eslint/no-proto": "error", + "eslint/no-shadow": "error", + "eslint/no-underscore-dangle": "off", + "eslint/no-unmodified-loop-condition": "off", + "eslint/no-unused-vars": [ + "error", + { + "args": "all", + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^$", + "caughtErrors": "all", + "caughtErrorsIgnorePattern": "^_", + "destructuredArrayIgnorePattern": "^_", + "ignoreRestSiblings": false + } + ], + "eslint/no-useless-catch": "off", + "eslint/no-var": "error", + "eslint/prefer-const": "error", + "eslint/prefer-regex-literals": [ + "error", + { + "disallowRedundantWrapping": true + } + ], + "eslint/preserve-caught-error": "off", + "eslint/sort-imports": "off", + "import/no-cycle": "off", + "import/no-named-as-default": "off", + "import/no-named-as-default-member": "off", + "import/no-self-import": "error", + "import/no-unassigned-import": "off", + "typescript/array-type": [ + "error", + { + "default": "array-simple" + } + ], + "typescript/consistent-type-assertions": [ + "error", + { + "assertionStyle": "as" + } + ], + "typescript/consistent-type-imports": "error", + "typescript/no-duplicate-enum-values": "error", + "typescript/no-duplicate-type-constituents": [ + "error", + { + "ignoreUnions": true + } + ], + "typescript/no-explicit-any": "error", + "typescript/no-extra-non-null-assertion": "error", + "typescript/no-extraneous-class": "off", + "typescript/no-misused-new": "error", + "typescript/no-non-null-asserted-optional-chain": "off", + "typescript/no-redundant-type-constituents": "off", + "typescript/no-this-alias": [ + "error", + { + "allowDestructuring": true + } + ], + "typescript/no-unnecessary-type-assertion": "off", + "typescript/no-useless-empty-export": "error", + "typescript/no-wrapper-object-types": "error", + "typescript/prefer-as-const": "error", + "typescript/triple-slash-reference": "error", + "unicorn/consistent-function-scoping": "off", + "unicorn/no-array-for-each": "off", + "unicorn/no-array-reverse": "error", + "unicorn/no-array-sort": "error", + "unicorn/no-empty-file": "off", + "unicorn/no-null": "off", + "unicorn/no-useless-fallback-in-spread": "off", + "unicorn/numeric-separators-style": "error", + "unicorn/prefer-node-protocol": "error", + "unicorn/prefer-spread": "off", + "typescript/no-unsafe-type-assertion": "off" + }, + "overrides": [ + { + "files": [ + "**/scripts/**", + "**/test/**", + "**/tests/**", + "**/.config/**", + "**/.git-hooks/**", + "**/.github/**", + "**/.claude/hooks/**", + "**/.claude/skills/**", + "**/.claude/workflows/**" + ], + "rules": {} + }, + { + "files": [ + "**/template/base/universal/.claude/**", + "**/template/base/universal/.config/fleet/**", + "**/template/base/universal/.git-hooks/**", + "**/template/base/universal/scripts/fleet/**", + "**/template/base/universal/test/fleet/**" + ], + "rules": {} + }, + { + "files": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"], + "rules": { + "eslint/no-unused-vars": "off" + } + }, + { + "files": [ + "**/scripts/fleet/build-hook-bundle.mts", + "**/scripts/fleet/build-hook-snapshot.mts", + "**/scripts/fleet/build-snapshot-launcher.mts", + "**/scripts/fleet/fetch-fleet-pack.mts", + "**/scripts/fleet/gen/hook-dispatch.mts", + "**/scripts/fleet/gen/hook-validators.mts", + "**/scripts/fleet/lib/stable-alias.mts", + "**/scripts/fleet/lockstep/emit-mirror-globs.mts", + "**/scripts/fleet/sync-oxlint-rules.mts", + "**/scripts/fleet/update.mts", + "**/scripts/fleet/update/fleet-pins.mts", + "**/scripts/repo/dogfood.mts", + "**/scripts/repo/commit-cascade/fixers/mirror-mode.mts" + ], + "rules": {} + } + ], + "ignorePatterns": [ + "**/node_modules/**", + "scripts/repo/bootstrap/**", + "**/*.d.ts", + "**/wasm_exec.js" + ] +} diff --git a/.config/repo/rolldown.config.mts b/.config/repo/rolldown.config.mts index b7757dbd..7543ee7d 100644 --- a/.config/repo/rolldown.config.mts +++ b/.config/repo/rolldown.config.mts @@ -6,8 +6,6 @@ import type { Plugin, RolldownOptions } from 'rolldown' import { getEnvValue } from '@socketsecurity/lib-stable/env/rewire' -import { defineGuardedPlugin } from '../fleet/rolldown/define-guarded.mts' - const rootPath = path.resolve(import.meta.dirname, '../..') const require = createRequire(import.meta.url) @@ -83,17 +81,12 @@ const config: RolldownOptions = { sourcemap: !minify, }, platform: 'node', - plugins: [ - // `defineGuarded` keys are dotted member chains. Source may spell the - // access with a dot or with quoted brackets — TypeScript forces - // `process.env['X']` on index-signature types — and both normalize to this - // same key. The `INLINED_*` name follows the fleet convention (see - // socket-cli) for build-inlined values. - defineGuardedPlugin({ + transform: { + define: { 'process.env.INLINED_EXTENSION_VERSION': JSON.stringify(extensionVersion), - }), - stageParserWasmPlugin(), - ], + }, + }, + plugins: [stageParserWasmPlugin()], // The sources are `.mts` (the fleet's sources-are-mts rule) and import each // other extensionlessly, which rolldown's default extension list does not // cover — without `.mts` here every relative import fails to resolve. diff --git a/.config/repo/tsconfig.json b/.config/repo/tsconfig.json index 3cdf785d..e6c54d01 100644 --- a/.config/repo/tsconfig.json +++ b/.config/repo/tsconfig.json @@ -1,5 +1,38 @@ { - "extends": ["../fleet/tsconfig.base.json", "./tsconfig.check.json"], + "compilerOptions": { + "allowJs": false, + "composite": false, + "declarationMap": false, + "esModuleInterop": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "incremental": false, + "isolatedModules": true, + "lib": ["DOM", "ES2024"], + "noEmitOnError": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noUncheckedSideEffectImports": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": false, + "strict": true, + "strictNullChecks": true, + "target": "ES2024", + "useUnknownInCatchVariables": true, + "verbatimModuleSyntax": true, + "allowImportingTsExtensions": true, + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "bundler", + "noEmit": true, + "types": ["node", "vscode"] + }, "include": ["../../src/**/*.mts", "../../src/**/*.d.ts"], - "exclude": ["../../node_modules"] + "exclude": ["../../node_modules", "../../out"], + "extends": "./tsconfig.check.json" } diff --git a/.config/repo/vitest.local.mts b/.config/repo/vitest.local.mts new file mode 100644 index 00000000..9f1c5f68 --- /dev/null +++ b/.config/repo/vitest.local.mts @@ -0,0 +1,26 @@ +import path from 'node:path' +import { defineConfig } from 'vitest/config' + +const root = path.resolve(import.meta.dirname, '../..') + +export default defineConfig({ + resolve: { + alias: { + vscode: path.join(root, 'test/stubs/vscode.mts'), + }, + }, + test: { + setupFiles: [path.join(root, 'test/repo/vitest.setup.mts')], + include: ['test/repo/unit/**/*.test.mts'], + exclude: [ + 'test/**/*.fuzz.mts', + 'test/repo/unit/test-extension.test.mts', + 'test/repo/unit/test-extension-auth.test.mts', + 'test/repo/unit/scripts/install-claude-plugins.test.mts', + ], + testTimeout: 15_000, + hookTimeout: 15_000, + pool: 'forks', + maxWorkers: 4, + }, +}) diff --git a/.git-hooks/_shared/push/repo-gates.mts b/.git-hooks/_shared/push/repo-gates.mts index 2d2922ef..ad8ecbd6 100644 --- a/.git-hooks/_shared/push/repo-gates.mts +++ b/.git-hooks/_shared/push/repo-gates.mts @@ -180,12 +180,17 @@ export const scanFastChecks = (ranges: readonly string[] = []): number => { if (!lintScript) { return 0 } - // Extract the local node-script path from a `node [args]` lint script - // (the fleet shape is `node scripts/fleet/lint.mts`). A non-node lint script - // can't be run directly here — skip rather than risk a pnpm reinstall. const m = /^node\s+(\S+\.[cm]?[jt]s)\b/.exec(lintScript.trim()) - if (!m || !existsSync(m[1]!)) { - return 0 + if (!m) { + const result = spawnSync('pnpm', ['run', 'lint'], { + env: { ...process.env, CI: 'true' }, + stdioString: true, + }) + showCheckResult(result) + return result.status ?? 1 + } + if (!existsSync(m[1]!)) { + return 1 } const scopeArgs = ranges.length > 0 ? ranges.map(range => `--range=${range}`) : ['--all'] diff --git a/.github/workflows/ci-gates.yml b/.github/workflows/ci-gates.yml index 323b625e..4662fbd3 100644 --- a/.github/workflows/ci-gates.yml +++ b/.github/workflows/ci-gates.yml @@ -68,7 +68,9 @@ jobs: - name: Check repository uses: ./.github/actions/fleet/run-script with: - main-script: pnpm run check --all + main-script: node scripts/fleet/check.mts --all + - name: Check standalone commands + run: pnpm run check test: name: Test (${{ matrix.os }}) @@ -112,7 +114,7 @@ jobs: uses: ./.github/actions/fleet/run-script with: setup-script: pnpm run build - main-script: pnpm test --ci + main-script: pnpm test full-test: name: Full test (${{ matrix.os }}) @@ -156,4 +158,4 @@ jobs: uses: ./.github/actions/fleet/run-script with: setup-script: pnpm run build - main-script: pnpm test --all + main-script: pnpm run test:full diff --git a/.github/workflows/cron-weekly-fuzz.yml b/.github/workflows/cron-weekly-fuzz.yml index b93acb61..2c6e7616 100644 --- a/.github/workflows/cron-weekly-fuzz.yml +++ b/.github/workflows/cron-weekly-fuzz.yml @@ -401,7 +401,7 @@ jobs: GH_TOKEN: ${{ github.token }} SDXGEN_GITHUB_TOKEN: ${{ steps.sdxgen-token.outputs.token }} FLEET_TEST_FUZZ: '1' - run: pnpm run test --all + run: pnpm run test:full - name: Run the JS fuzz campaign env: GH_TOKEN: ${{ github.token }} diff --git a/.toolingignore b/.toolingignore new file mode 100644 index 00000000..f42bb140 --- /dev/null +++ b/.toolingignore @@ -0,0 +1,3 @@ +scripts/repo/bootstrap/ +test/repo/fixtures/ +.config/repo/socket-wheelhouse-schema.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 048450d1..effb2d6a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -23,7 +23,7 @@ "label": "Socket: test", "type": "process", "command": "pnpm", - "args": ["test", "--all"], + "args": ["test"], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [], "group": { "kind": "test", "isDefault": true } diff --git a/README.md b/README.md index 8e5cd1a2..4d2525fe 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Press `F5` in VS Code to build the extension and launch an Extension Development Run the `Socket: watch` task or `pnpm run watch` to rebuild on edits. Reload the Extension Development Host to load each rebuild. -Run the `Socket: test` task or `pnpm test --all` for the full test suite. Use `pnpm test test/repo/unit/auth.test.mts` to run one test file. +Run the `Socket: test` task or `pnpm test` for the standalone unit suite. Run `pnpm run sync-fleet` before using the Fleet-backed coverage, fuzz, extension-host, or release commands. Use `pnpm run test:full` for the hydrated suite. Use `pnpm test test/repo/unit/auth.test.mts` to run one test file. Run `pnpm run package-for-vscode` to build and package the production `.vsix`. diff --git a/package.json b/package.json index 81308e93..d60a2889 100644 --- a/package.json +++ b/package.json @@ -40,227 +40,38 @@ "provenance": true }, "scripts": { - "ai-balancer": "node scripts/fleet/ai/balancer/launch.mts", - "ai-balancer:auth": "node scripts/fleet/ai/balancer/login.mts", - "ai-balancer:doctor": "node scripts/fleet/ai/balancer/doctor.mts", - "ai-balancer:refresh": "node scripts/fleet/ai/balancer/service.mts refresh", - "ai-balancer:savings": "node scripts/fleet/ai-balancer-savings.mts", - "ai-balancer:service": "node scripts/fleet/ai/balancer/service.mts", - "ai:drive:check": "node scripts/fleet/check/browser-extension-build-current.mts", - "ai:drive:doctor": "node scripts/fleet/ai/browser/bridge/doctor.mts", - "ai:drive:setup": "node scripts/fleet/setup/browser/bridge.mts", - "ai:drive:verify": "node scripts/fleet/ai/browser/bridge/verify-installed.mts", - "ai:odai:cache": "node scripts/fleet/ai/odai/run.mts cache", - "ai:odai:ci": "node scripts/fleet/ai/odai/ci.mts", - "ai:odai:diagnose": "node scripts/fleet/ai/odai/run.mts diagnose", - "ai:read": "node scripts/fleet/ai/bounded-reader.mts", - "audit:consumer-source": "node scripts/fleet/audit/consumer-source.mts", - "backup": "node scripts/fleet/backup/work/run.mts", - "browser:advice": "node scripts/fleet/ai/browser/agent/jev/run.mts", - "browser:bridge": "node scripts/fleet/ai/browser/bridge/cli.mts", - "browser:open-setup": "node scripts/fleet/ai/browser/open-setup.mts", "build": "pnpm run build:dev", - "build:check": "node scripts/fleet/commands/run.mts build check", "build:dev": "rolldown -c .config/repo/rolldown.config.mts", - "build:hook-bundle": "node scripts/fleet/build-hook-bundle.mts", - "build:hook-snapshot": "node scripts/fleet/build-hook-snapshot.mts", - "build:oxlint-bundle": "node scripts/fleet/build-oxlint-bundle.mts", "build:prod": "MINIFY=1 rolldown -c .config/repo/rolldown.config.mts", - "build:snapshot-launcher": "node scripts/fleet/build-snapshot-launcher.mts", - "build:test": "node scripts/fleet/commands/run.mts build test", - "build:update": "node scripts/fleet/commands/run.mts build update", - "check": "node scripts/fleet/check.mts", - "check:deadcode": "node scripts/fleet/analysis/fallow.mts deadcode", - "check:deps": "node scripts/fleet/check.mts --category=deps", - "check:duplication": "node scripts/fleet/analysis/fallow.mts duplication", - "check:fix": "node scripts/fleet/check/fix.mts", - "check:fleet": "node scripts/fleet/check.mts", - "check:hooks": "node scripts/fleet/check.mts --category=hooks", - "check:paths": "node scripts/fleet/check/paths-are-valid.mts", - "check:test": "node scripts/fleet/commands/run.mts check test", - "check:test-budget-headroom": "node scripts/fleet/check/test-budget-headroom.mts", - "check:types": "node scripts/fleet/check.mts --category=types", - "check:update": "node scripts/fleet/commands/run.mts check update", - "check:workspace-installation": "node scripts/fleet/check/workspace-installation.mts", - "ci:check": "node scripts/fleet/commands/run.mts ci check", - "ci:diagnose": "node .claude/skills/fleet/agent-ci/run.mts", + "check": "pnpm run build && pnpm run typecheck && pnpm run lint && pnpm run format:check", "ci:fix": "node scripts/fleet/ci/fix/run.mts", - "ci:fix:preview": "node scripts/fleet/ci/fix/preview.mts", "ci:gates": "node scripts/fleet/ci/gates/run.mts", - "ci:local": "node scripts/fleet/ci/local/run.mts run --all --quiet --github-token --pause-on-failure", - "ci:test": "node scripts/fleet/commands/run.mts ci test", - "ci:update": "node scripts/fleet/commands/run.mts ci update", - "clean": "node scripts/fleet/clean.mts", - "coordination:claim": "node scripts/fleet/coordination/claim.mts", - "coordination:mail": "node scripts/fleet/coordination/mail.mts", + "clean": "node scripts/repo/clean.mts", "cover": "node scripts/fleet/cover.mts", "cover:aggregate": "node scripts/fleet/cover-aggregate.mts", - "cover:allowance": "node scripts/fleet/cover/allowance.mts", - "cover:balance": "node scripts/fleet/cover/balance.mts", - "cover:check": "node scripts/fleet/commands/run.mts cover check", - "cover:fix": "node scripts/fleet/cover/fix.mts", - "cover:shard": "node scripts/fleet/cover-shard.mts", - "cover:test": "node scripts/fleet/commands/run.mts cover test", - "cover:types": "node scripts/fleet/cover/types/run.mts", - "cover:update": "node scripts/fleet/commands/run.mts cover update", - "crates:auth": "node scripts/fleet/registry/cargo/auth.mts", - "credentials": "node scripts/fleet/credentials/run.mts", - "credentials:gh": "node scripts/fleet/credentials/gh/run.mts", - "credentials:migrate": "node scripts/fleet/credentials/migrate.mts", - "depot:auth": "node scripts/fleet/registry/depot/browser-auth.mts", - "doctor": "node scripts/fleet/doctor.mts", - "doctor:auth": "node scripts/fleet/check/setup-is-prompt-less.mts", - "doctor:credentials": "node scripts/fleet/credentials/doctor.mts", - "fix": "node scripts/fleet/fix.mts", - "fix:js": "node scripts/fleet/fix.mts --js", - "fix:repo": "node scripts/fleet/fix.mts --repo", - "fleet:status": "node scripts/repo/bootstrap/fleet.mjs --status", - "fleet:update": "node scripts/repo/bootstrap/fleet.mjs", - "fmt:js": "node scripts/fleet/format.mts", - "format": "node scripts/fleet/format.mts", - "format:check": "node scripts/fleet/format.mts --check", - "format:test": "node scripts/fleet/commands/run.mts format test", - "format:update": "node scripts/fleet/commands/run.mts format update", - "gen:glyph": "node scripts/fleet/gen/glyph.mts", - "gen:mcp:config": "node scripts/fleet/mcp/config.mts", - "gh:auth": "node scripts/fleet/gh-auth.mts", - "git:admin:merge": "node scripts/fleet/git/admin/merge.mts", - "git:admin:push": "node scripts/fleet/git/admin/push.mts", - "git:deliver": "node scripts/fleet/git/deliver/cli.mts", - "git:history": "node scripts/fleet/git/history/cli.mts", - "github:browser": "node scripts/fleet/ai/browser/drive/github.com/auth/run.mts", - "hide-comments": "node scripts/fleet/github/comments/hide.mts", - "hooks:global:sync": "node scripts/fleet/sync-global-hooks.mts", - "hooks:repo:sync": "node scripts/repo/bootstrap/fleet.mjs", - "hooks:sync": "node scripts/fleet/hooks/sync.mts", - "integrity-refresh": "node scripts/fleet/external-tools/refresh.mts", - "jev:benchmark": "node scripts/fleet/ai/eval/cli.mts", - "jev:events": "node scripts/fleet/ai/balancer/events/cli.mts", - "jev:revision": "node scripts/fleet/ai/classifiers/cli.mts", - "lint": "node scripts/fleet/lint.mts", - "lint:check": "node scripts/fleet/commands/run.mts lint check", - "lint:fix": "node scripts/fleet/lint/fix.mts", - "lint:js": "node scripts/fleet/lint.mts", - "lint:test": "node scripts/fleet/commands/run.mts lint test", - "lint:update": "node scripts/fleet/commands/run.mts lint update", - "lockstep": "node scripts/fleet/lockstep.mts", - "lockstep:assist": "node scripts/fleet/lockstep/assist/run.mts", - "lockstep:check": "node scripts/fleet/commands/run.mts lockstep check", - "lockstep:emit-mirror-globs": "node scripts/fleet/lockstep-emit-mirror-globs.mts", - "lockstep:emit-schema": "node scripts/fleet/lockstep-emit-schema.mts", - "lockstep:fix": "node scripts/fleet/commands/run.mts lockstep fix", - "lockstep:test": "node scripts/fleet/commands/run.mts lockstep test", - "lockstep:update": "node scripts/fleet/lockstep/update.mts", - "mcp:1password": "node scripts/fleet/mcp/1password/run.mts", - "mcp:connect": "node scripts/fleet/mcp/connect.mts", - "mcp:pgbot": "node scripts/fleet/mcp/pgbot/run.mts", - "mcp:reset": "node scripts/fleet/mcp/reset.mts", - "mcp:schemas:check": "node scripts/fleet/mcp/schemas.mts check", - "mcp:schemas:save": "node scripts/fleet/mcp/schemas.mts save", - "mcp:status": "node scripts/fleet/mcp/connect.mts --status", - "npm:approve": "node scripts/fleet/npm/approve.mts", - "npm:auth": "node scripts/fleet/npm/auth/run.mts", - "npm:auth:browser": "node scripts/fleet/npm-auth-browser.mts", + "fix": "pnpm run lint:fix && pnpm run format", + "format": "oxfmt --write --ignore-path .toolingignore --config .config/repo/oxfmtrc.json src test/repo scripts/repo .config/repo", + "format:check": "oxfmt --check --ignore-path .toolingignore --config .config/repo/oxfmtrc.json src test/repo scripts/repo .config/repo", + "lint": "oxlint --ignore-path .toolingignore --config .config/repo/oxlintrc.json src scripts/repo .config/repo", + "lint:fix": "oxlint --ignore-path .toolingignore --config .config/repo/oxlintrc.json --fix src scripts/repo .config/repo", "npm:dispatch": "node scripts/fleet/npm/publish/run.mts", - "npm:inventory": "node scripts/fleet/registry/npm/account/inventory/read.mts", "npm:release-record": "node scripts/fleet/release/record/run.mts", - "npm:scan": "node scripts/fleet/npm/scan.mts", - "npm:staged": "node scripts/fleet/npm/staged.mts", - "npm:trust": "node scripts/fleet/registry/npm/settings/trust.mts", - "npm:trust:browser": "node scripts/fleet/registry/npm/settings/trusted-publisher/browser.mts", - "npm:trust:migrate": "node scripts/fleet/npm/trusted-publisher/run.mts", - "offload:model": "node scripts/fleet/offload-model.mts", "package-for-vscode": "pnpm run build:prod && vsce package --no-dependencies", "preflight": "node scripts/repo/bootstrap/fleet.mjs --quiet && node scripts/fleet/preflight.mts", "prepare": "node scripts/repo/bootstrap/prepare.mts && node scripts/fleet/install-git-hooks.mts && node scripts/fleet/prepare.mts", "prepublishOnly": "echo 'ERROR: Use GitHub Actions workflow for publishing' && exit 1", - "prose": "node scripts/fleet/prose/run.mts", - "prune:branch-backups": "node scripts/fleet/backup/branches/run.mts prune", - "prune:gha-caches": "node scripts/fleet/workflow/caches/prune.mts", - "publish:npm": "node scripts/fleet/npm/publish/run.mts", - "release:github": "node scripts/fleet/release/github/remote.mts", - "release:hint": "node scripts/fleet/release/hint.mts", "release:nightly:plan": "node scripts/fleet/release/nightly/cli.mts", - "review:comments": "node scripts/fleet/comment-review/run.mts", - "review:pr": "node scripts/fleet/ai/review/jev/run.mts", - "ruleset:bypass": "node scripts/fleet/grant-ruleset-bypass.mts", - "search:code": "node scripts/fleet/ai/search/run.mts", - "security": "node scripts/fleet/security.mts", - "setup-all": "node scripts/fleet/setup/index.mts", - "setup-security-tools": "node scripts/fleet/setup/security/tools.mts", - "setup:0-mise": "node scripts/fleet/setup/mise.mts --bootstrap", - "setup:1-token": "node scripts/fleet/setup/token.mts", - "setup:1password": "node scripts/fleet/setup/one-password.mts", - "setup:3-hook-snapshot": "node scripts/fleet/setup/hook-snapshot.mts", - "setup:4-repo-steps": "node scripts/fleet/setup/repo-steps.mts", - "setup:ai-clients": "node scripts/fleet/setup/ai-clients.mts", - "setup:brew": "node scripts/fleet/setup/brew.mts", - "setup:ci:local": "node scripts/fleet/ci/local/setup.mts", - "setup:ci:remote": "node scripts/fleet/ci/remote/setup.mts", - "setup:credentials": "node scripts/fleet/setup/credentials.mts", - "setup:fff": "node scripts/fleet/setup/fff.mts", - "setup:github:app": "node scripts/fleet/github/credentials/setup.mts", - "setup:go": "node scripts/fleet/setup/go.mts", - "setup:hook-snapshot": "node scripts/fleet/setup/hook-snapshot.mts", - "setup:iterm2": "node scripts/fleet/setup/iterm2/run.mts", - "setup:mise": "node scripts/fleet/setup/mise.mts", - "setup:offload-providers": "node scripts/fleet/setup/offload-providers.mts", - "setup:pgbot": "node scripts/fleet/setup/pgbot.mts", - "setup:python": "node scripts/fleet/setup/python.mts", - "setup:refero": "node scripts/fleet/setup/refero.mts", - "setup:repo-steps": "node scripts/fleet/setup/repo-steps.mts", - "setup:rust": "node scripts/fleet/setup/rust.mts", "setup:rust-coverage": "node scripts/fleet/setup/rust-coverage.mts", - "setup:security": "node scripts/fleet/setup/security/run.mts", - "setup:security-tools": "node scripts/fleet/setup/security/tools.mts", "setup:sfw-ca": "node scripts/fleet/setup/sfw-ca.mts", - "setup:token:rotate": "node scripts/fleet/setup/token.mts --rotate", - "setup:xcode": "node scripts/fleet/setup/xcode-license.mts", - "setup:xcode-license": "node scripts/fleet/setup/xcode-license.mts", - "slack:auth": "node scripts/fleet/setup/slack-token.mts", - "slack:token": "node scripts/fleet/setup/slack-token.mts", - "soak:bypass": "node scripts/fleet/soak-bypass.mts", - "soak:check": "node scripts/fleet/check/soak-time-is-consistent.mts", - "socket-wheelhouse:emit-schema": "node scripts/fleet/socket-wheelhouse-emit-schema.mts", - "spend-usage": "node scripts/fleet/spend-usage.mts", - "strip:ai-tags": "node scripts/fleet/strip-ai-tags.mts", - "sweep": "node scripts/fleet/sweep.mts", - "sweep:worktrees": "node scripts/fleet/worktree-sweep.mts", - "sweep:worktrees:visit": "node scripts/fleet/worktree/sweep/run.mts", "sync-fleet": "node scripts/repo/bootstrap/fleet.mjs", - "sync-global-hooks": "node scripts/fleet/sync-global-hooks.mts", "sync-oxlint-rules": "node scripts/fleet/sync-oxlint-rules.mts", - "sync-package-manager-pins": "node scripts/fleet/sync-package-manager-pins.mts", - "test": "node scripts/fleet/test.mts", - "test:allowance": "node scripts/fleet/test/allowance.mts", - "test:balance": "node scripts/fleet/test/balance.mts", - "test:check": "node scripts/fleet/commands/run.mts test check", + "test": "vitest run --config .config/repo/vitest.local.mts", "test:extension": "node scripts/repo/test-extension.mts", "test:extension-auth": "node scripts/repo/test-extension-auth.mts", - "test:fast": "node scripts/fleet/test/fast.mts", - "test:fix": "node scripts/fleet/test/fix.mts", + "test:full": "node scripts/fleet/test.mts --all", "test:fuzz": "node scripts/repo/fuzz.mts", - "test:mid": "node scripts/fleet/test/mid.mts", - "test:profile": "node scripts/fleet/test/profile.mts", - "test:slow": "node scripts/fleet/test/slow.mts", - "test:test": "node scripts/fleet/commands/run.mts test test", - "test:update": "node scripts/fleet/commands/run.mts test update", - "type": "node scripts/fleet/type.mts", - "types:check": "node scripts/fleet/commands/run.mts types check", - "types:fix": "node scripts/fleet/types/fix.mts", - "types:test": "node scripts/fleet/commands/run.mts types test", - "types:update": "node scripts/fleet/commands/run.mts types update", - "update": "node scripts/fleet/update.mts", - "update:check": "node scripts/fleet/weekly-update.mts --check-updates", - "update:chrome": "node scripts/fleet/update/chrome.mts", - "update:pnpm": "node scripts/fleet/update/pnpm.mts", - "watch": "pnpm run build:dev --watch", - "weekly-update": "node scripts/fleet/weekly-update.mts", - "weekly-update:ci": "gh workflow run cron-weekly-update.yml", - "worktree:create": "node scripts/fleet/worktree/create/run.mts", - "notion:planning:update": "node scripts/fleet/notion/planning/update.mts", - "notion:standup:update": "node scripts/fleet/notion/standup/update.mts", - "workflow:actions:lock": "node scripts/fleet/workflow/actions-lock/run.mts" + "typecheck": "tsc --noEmit -p .config/repo/tsconfig.json", + "watch": "pnpm run build:dev --watch" }, "dependencies": { "@socketsecurity/lib": "catalog:", diff --git a/scripts/repo/clean.mts b/scripts/repo/clean.mts new file mode 100644 index 00000000..b26331fa --- /dev/null +++ b/scripts/repo/clean.mts @@ -0,0 +1,8 @@ +import { rm } from 'node:fs/promises' +import path from 'node:path' +import process from 'node:process' + +const root = process.cwd() +for (const entry of ['coverage', 'dist', 'out', '.vitest']) { + await rm(path.join(root, entry), { force: true, recursive: true }) +} diff --git a/src/extension.mts b/src/extension.mts index 247f534e..c7fffc56 100644 --- a/src/extension.mts +++ b/src/extension.mts @@ -8,14 +8,6 @@ import { activate as activateEditorConfig } from './data/editor-config.mts' import { activate as activateFiles } from './ui/file.mts' import { initializeCacheStorage } from './ui/purl-alerts-and-scores/manager.mts' -// `process.env['INLINED_EXTENSION_VERSION']` is replaced at build time with -// the package.json version by the rolldown build (.config/repo/rolldown.config.mts → -// defineGuardedPlugin). The fleet-canonical `INLINED_*` env-var convention -// (see socket-cli) marks build-inlined values clearly. Quoted (bracket) -// property access is required: `process.env` is an index-signature type, so -// TypeScript (TS4111) rejects dot access; `defineGuarded` normalizes the -// bracket form to the dotted define key when matching. - export async function activate(context: vscode.ExtensionContext) { initializeCacheStorage(context.globalStorageUri.fsPath) activateEditorConfig(context) diff --git a/test/repo/unit/define-guarded.test.mts b/test/repo/unit/define-guarded.test.mts deleted file mode 100644 index e13b305f..00000000 --- a/test/repo/unit/define-guarded.test.mts +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @file Tests for the guarded compile-time define plugin - * (.config/fleet/rolldown/define-guarded.mts). Locks in that a single dotted - * define - * key matches dot, single-quote, and double-quote member access alike (TS - * forces quoted bracket access on `process.env`), that TS source is parsed - * (not rejected as JS), and that write / dynamic positions are left - * untouched. - */ - -import { describe, expect, test } from 'vitest' - -import { defineGuardedPlugin } from '../../../.config/fleet/rolldown/define-guarded.mts' - -// Exported `function` declaration: satisfies both fleet rules — -// socket/prefer-function-declaration (no module-scope arrow) and -// socket/export-top-level-functions (top-level functions must be exported). -export function run(code: string, id = 'src/example.ts'): string | undefined { - const plugin = defineGuardedPlugin({ - 'process.env.INLINED_EXTENSION_VERSION': JSON.stringify('2.0.3'), - }) - // rolldown's transform hook signature is (code, id); call it directly. - const transform = plugin.transform as ( - this: unknown, - code: string, - id: string, - ) => { code: string } | undefined - const result = transform.call({}, code, id) - return result?.code -} - -describe('defineGuardedPlugin', () => { - test('rewrites dot access', () => { - const out = run('const a = process.env.INLINED_EXTENSION_VERSION') - expect(out).toContain('"2.0.3"') - expect(out).not.toContain('INLINED_EXTENSION_VERSION') - }) - - test('rewrites single-quote bracket access', () => { - const out = run("const b = process.env['INLINED_EXTENSION_VERSION']") - expect(out).toContain('"2.0.3"') - expect(out).not.toContain('INLINED_EXTENSION_VERSION') - }) - - test('rewrites double-quote bracket access', () => { - const out = run('const c = process.env["INLINED_EXTENSION_VERSION"]') - expect(out).toContain('"2.0.3"') - expect(out).not.toContain('INLINED_EXTENSION_VERSION') - }) - - test('parses TypeScript source (type annotations do not abort the rewrite)', () => { - const out = run( - 'export function f(ctx: vscode.ExtensionContext): string {\n' + - " return process.env['INLINED_EXTENSION_VERSION']\n" + - '}\n', - ) - expect(out).toContain('"2.0.3"') - }) - - test('parses .tsx source', () => { - const out = run( - 'const e =
{process.env["INLINED_EXTENSION_VERSION"]}
', - 'src/example.tsx', - ) - expect(out).toContain('"2.0.3"') - }) - - test('leaves an assignment target untouched', () => { - const code = "process.env['INLINED_EXTENSION_VERSION'] = 'x'" - expect(run(code)).toBeUndefined() - }) - - test('leaves dynamic computed access untouched', () => { - const code = - 'const k = "INLINED_EXTENSION_VERSION"\nconst d = process.env[k]' - expect(run(code)).toBeUndefined() - }) - - test('does not rewrite an unrelated env var', () => { - const code = "const u = process.env['SOMETHING_ELSE']" - expect(run(code)).toBeUndefined() - }) -}) diff --git a/test/repo/unit/rolldown.config-extension-version.test.mts b/test/repo/unit/rolldown.config-extension-version.test.mts new file mode 100644 index 00000000..015aa096 --- /dev/null +++ b/test/repo/unit/rolldown.config-extension-version.test.mts @@ -0,0 +1,41 @@ +import { readFileSync } from 'node:fs' + +import { rolldown } from 'rolldown' +import { expect, test } from 'vitest' + +import config from '../../../.config/repo/rolldown.config.mts' + +test('inlines static version reads and preserves strings and source maps', async () => { + const source = [ + 'export const dot = process.env.INLINED_EXTENSION_VERSION', + "export const bracket = process.env['INLINED_EXTENSION_VERSION']", + "export const literal = 'process.env.INLINED_EXTENSION_VERSION'", + ].join('\n') + const bundle = await rolldown({ + transform: config.transform, + input: 'version.mts', + plugins: [ + { + name: 'version-fixture', + resolveId: () => 'version.mts', + load: () => source, + }, + ], + }) + try { + const { + output: [chunk], + } = await bundle.generate({ format: 'esm', sourcemap: true }) + const { version } = JSON.parse( + readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'), + ) + const result = await import( + 'data:text/javascript,' + encodeURIComponent(chunk.code) + ) + expect([result.dot, result.bracket]).toEqual([version, version]) + expect(result.literal).toBe('process.env.INLINED_EXTENSION_VERSION') + expect(chunk.map?.sourcesContent).toContain(source) + } finally { + await bundle.close() + } +}) diff --git a/test/repo/vitest.setup.mts b/test/repo/vitest.setup.mts new file mode 100644 index 00000000..802fa238 --- /dev/null +++ b/test/repo/vitest.setup.mts @@ -0,0 +1,3 @@ +import nock from 'nock' + +nock.disableNetConnect() diff --git a/tsconfig.json b/tsconfig.json index b3cce1b7..4de6d333 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "./.config/fleet/tsconfig.base.json" + "extends": "./.config/repo/tsconfig.json" }