Files
opencode-manager/backend/test/helpers/internal-test-app.ts
T
Chris Scott e0331b43bf feat(secrets): repository secrets and variables injected into agent shells and terminals
Add a GitHub Actions-style store for secrets and variables so tests can read
credentials from the environment without .env files in the repo.

- secrets table keyed by kind, repo (NULL for global) and environment;
  secrets are encrypted with encryptSecret and write-only, variables are plain
  text. Names follow GitHub's rules and reject Manager-reserved names.
- Global (/api/secrets, /api/variables) and repo
  (/api/repos/:id/secrets|variables) routes.
- The trusted .ocm/project.json gains environment and env fields that map
  names to ${{ secrets.X }} / ${{ vars.X }} expressions. Both are part of the
  trust hash; files without them hash as before, so existing trust survives.
- RepoEnvService.resolveForDirectory resolves the repo and approved mapping
  for any directory, including worktrees outside the repo folder, with
  environment > repo > global precedence. It never throws.
- /api/internal/shell-env replaces /git-credentials/gh-env and feeds the
  ocm-gh-env plugin, the sandbox shell plan and TerminalService.create.
- The plugin masks injected secret values as *** in completed tool results.
- The sandbox shell plan is now the only source of the guest environment: the
  plugin pins OCM_SANDBOX_FORWARD_ENV and the shim forwards only those names.
2026-10-23 22:59:57 -04:00

47 lines
2.0 KiB
TypeScript

import { createInternalRoutes } from '../../src/routes/internal'
import { createStubOpenCodeClient } from './stub-opencode-client'
type CreateInternalRoutesParams = Parameters<typeof createInternalRoutes>
type InternalTestAppOverrides = Partial<{
scheduleService: CreateInternalRoutesParams[1]
notificationService: CreateInternalRoutesParams[2]
settingsService: CreateInternalRoutesParams[3]
openCodeClient: CreateInternalRoutesParams[4]
permissionModes: CreateInternalRoutesParams[5]
repoWorkspaces: CreateInternalRoutesParams[6]
gitAuthService: CreateInternalRoutesParams[7]
sessionGoals: CreateInternalRoutesParams[8]
multiRuns: CreateInternalRoutesParams[9]
changeWalkthroughService: CreateInternalRoutesParams[10]
sessionSandbox: CreateInternalRoutesParams[11]
repoEnvService: CreateInternalRoutesParams[12]
}>
function createStubRepoEnvService(): CreateInternalRoutesParams[12] {
return {
resolveForDirectory: async () => ({ env: {}, maskValues: [], missing: [] }),
} as unknown as CreateInternalRoutesParams[12]
}
export function createInternalTestApp(
db: CreateInternalRoutesParams[0],
overrides: InternalTestAppOverrides = {},
) {
return createInternalRoutes(
db,
overrides.scheduleService ?? ({} as CreateInternalRoutesParams[1]),
overrides.notificationService ?? ({} as CreateInternalRoutesParams[2]),
overrides.settingsService ?? ({} as CreateInternalRoutesParams[3]),
overrides.openCodeClient ?? createStubOpenCodeClient(),
overrides.permissionModes ?? ({} as CreateInternalRoutesParams[5]),
overrides.repoWorkspaces ?? ({} as CreateInternalRoutesParams[6]),
overrides.gitAuthService ?? ({} as CreateInternalRoutesParams[7]),
overrides.sessionGoals ?? ({} as CreateInternalRoutesParams[8]),
overrides.multiRuns ?? ({} as CreateInternalRoutesParams[9]),
overrides.changeWalkthroughService ?? ({} as CreateInternalRoutesParams[10]),
overrides.sessionSandbox ?? ({} as CreateInternalRoutesParams[11]),
overrides.repoEnvService ?? createStubRepoEnvService(),
)
}