Personal Telegram developer console for GitHub
feat/studio-g0-foundation
audit/commit-drilldown
audit/finalize-workspace-menu-security
audit/ops-actionability
audit/pr-menu-consolidation
audit/status-menu-consolidation
audit/telegram-menu-e2e
audit/telegram-menu-e2e-wave2
chore/actions-node24-runtime
cleanup/remove-diag
design/cloudflare-ops-read
docs/control-plane-2-7-design
docs/guide-v2-1-sync
docs/menu-audit-final-sync
docs/phase2-acceptance-closeout
docs/phase2-multifile-design
feat/bootstrap-worker
feat/cloudflare-ops-read
feat/cp2-multifile-final
feat/cp2-multifile-workspace
feat/cp3-github-write-final
feat/cp4-cloudflare-ops-final
feat/cp5-cicd-control-plane
feat/cp6-incident-manager
feat/cp7-automation-engine
feat/deep-file-browser
feat/final-delivery-16-20
feat/github-advanced-read
feat/in-app-guide-v2
feat/navigation-recovery-ux-v2
feat/ops-console-v2-1
feat/persistent-menu-code-input
feat/phase2-multifile-workspace
feat/phase2-multifile-workspace-v2
feat/plugin-foundation-v1
feat/safe-github-ops
feat/self-register-webhook
feat/studio-g0-foundation
feat/telegram-main-inline-menu
feat/telegram-pr-merge
feat/ux-platform-8-12
feat/v3a-readonly-copilot
feat/workspace-file-upload
feature/mobile-repo-browser
feature/multi-file-change-set
fix/approval-expiry-feedback
fix/callback-resilience-and-docs
fix/ci-actions-pagination
fix/cloudflare-fetch-binding
fix/editor-request-body-cap
fix/editor-safe-file-options
fix/issues-permission-release-empty-ux
fix/main-menu-callback-fallback
fix/phase2-file-editor-selection
fix/phase2-final-ux
fix/phase2-workspace-ref-persistence
fix/production-auto-deploy
fix/provider-write-error-feedback
fix/repository-id-navigation-fallback
fix/repository-pr-navigation
fix/telegram-callback-updates
fix/telegram-runtime-diagnostics
fix/workspace-editor-flow-v2
fix/workspace-recovery-validation
hardening/ci-zero-test-telegram-token
hardening/pr1-destructive-totp
hardening/pr2-kill-switch
main
multifile-workspace
nexa/edit-BwJEIIY3PW
nexa/edit-IPHT8irO7b
nexa/edit-b4Od3BIMYd
p2-multifile
phase2-20261005
phase2-20261005-a
phase2-20261005-b
phase2-20261005-c
phase2-20261005-d
phase2-20261005-e
phase2-20261005-f
phase2-20261005-g
phase2-20261005-h
phase2-20261005-i
phase2-20261005-j
phase2-20261005-k
phase2-20261005-l
phase2-20261005-m
phase2-20261005-n
phase2-20261005-o
phase2-20261005-p
phase2-20261005-q
phase2-20261005-r
phase2-20261005-s
phase2-20261005-t
phase2-20261005-u
phase2-20261005-v
phase2-20261005-w
phase2-20261005-x
phase2-20261005-y
phase2-20261005-z
phase2-acceptance-closeout
phase2-add-file-hotfix
phase2-change-set
phase2-design-20261005
phase2-design-final
phase2-implementation
phase2-multifile-implementation
phase2-multifile-spec
phase2-spec-final
phase2-workspace
phase2/multifile-workspace
plan/nexa-studio-v2-reviewed
security/remove-telegram-setup
spec/repository-workspace-editor
v3a/multifile
work/multifile
| 1 | import test from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { KillSwitch } from '../src/core/kill-switch.js'; |
| 4 | import { PluginRouter } from '../src/core/router.js'; |
| 5 | import { AutomationRunner } from '../src/core/automation-runner.js'; |
| 6 | import { DurableAutomationStoreClient } from '../src/core/automation-store.js'; |
| 7 | import { AutomationStore } from '../src/durable/automation-store.js'; |
| 8 | import { createAutomation } from '../src/core/automation.js'; |
| 9 | import { makeReplayState } from './helpers/replay-namespace.js'; |
| 10 | function registryFor(risk, execute) { |
| 11 | const actionId = `test.${risk.toLowerCase()}`; |
| 12 | const plugin = { |
| 13 | manifest: { id: 'test' }, |
| 14 | async resolveCallback() { |
| 15 | return { actionId, execute }; |
| 16 | } |
| 17 | }; |
| 18 | return { |
| 19 | getPlugins: () => [plugin], |
| 20 | getAction: () => ({ pluginId: 'test', actionId, risk }) |
| 21 | }; |
| 22 | } |
| 23 | const audit = { log() {} }; |
| 24 | const policy = { |
| 25 | evaluate: ({ action }) => ({ |
| 26 | allowed: true, |
| 27 | requiresApproval: false, |
| 28 | risk: action.risk |
| 29 | }) |
| 30 | }; |
| 31 | test('LOCKED kill switch allows READ but blocks WRITE before provider mutation', async () => { |
| 32 | let reads = 0, |
| 33 | writes = 0; |
| 34 | const killSwitch = new KillSwitch({ |
| 35 | store: { get: async () => ({ mode: 'LOCKED' }) } |
| 36 | }); |
| 37 | const readRouter = new PluginRouter({ |
| 38 | registry: registryFor('READ', async () => { |
| 39 | reads++; |
| 40 | return { ok: true }; |
| 41 | }), |
| 42 | policy, |
| 43 | audit, |
| 44 | killSwitch |
| 45 | }); |
| 46 | const writeRouter = new PluginRouter({ |
| 47 | registry: registryFor('WRITE', async () => { |
| 48 | writes++; |
| 49 | return { ok: true }; |
| 50 | }), |
| 51 | policy, |
| 52 | audit, |
| 53 | killSwitch |
| 54 | }); |
| 55 | assert.equal( |
| 56 | (await readRouter.dispatchCallback('x', { isOwner: true })).ok, |
| 57 | true |
| 58 | ); |
| 59 | const blocked = await writeRouter.dispatchCallback('x', { |
| 60 | isOwner: true, |
| 61 | approved: true |
| 62 | }); |
| 63 | assert.equal(blocked.ok, false); |
| 64 | assert.equal(blocked.killSwitchLocked, true); |
| 65 | assert.equal(reads, 1); |
| 66 | assert.equal(writes, 0); |
| 67 | }); |
| 68 | test('kill switch fails closed for WRITE when durable state cannot be read', async () => { |
| 69 | let writes = 0; |
| 70 | const killSwitch = new KillSwitch({ |
| 71 | store: { |
| 72 | get: async () => { |
| 73 | throw new Error('durable unavailable'); |
| 74 | } |
| 75 | } |
| 76 | }); |
| 77 | const router = new PluginRouter({ |
| 78 | registry: registryFor('WRITE', async () => { |
| 79 | writes++; |
| 80 | return { ok: true }; |
| 81 | }), |
| 82 | policy, |
| 83 | audit, |
| 84 | killSwitch |
| 85 | }); |
| 86 | const blocked = await router.dispatchCallback('x', { |
| 87 | isOwner: true, |
| 88 | approved: true |
| 89 | }); |
| 90 | assert.equal(blocked.ok, false); |
| 91 | assert.equal(blocked.killSwitchLocked, true); |
| 92 | assert.equal(writes, 0); |
| 93 | }); |
| 94 | test('LOCKED kill switch blocks automation advance before routing any step', async () => { |
| 95 | let routed = 0; |
| 96 | const durable = makeReplayState(); |
| 97 | const store = new DurableAutomationStoreClient({ |
| 98 | ownerId: '123', |
| 99 | namespace: { |
| 100 | idFromName: (name) => name, |
| 101 | get: () => ({ |
| 102 | fetch: (url, options) => |
| 103 | new AutomationStore(durable).fetch(new Request(url, options)) |
| 104 | }) |
| 105 | } |
| 106 | }); |
| 107 | const runner = new AutomationRunner({ |
| 108 | router: { |
| 109 | dispatchCallback: async () => { |
| 110 | routed++; |
| 111 | return { ok: true }; |
| 112 | } |
| 113 | }, |
| 114 | store, |
| 115 | killSwitch: new KillSwitch({ |
| 116 | store: { get: async () => ({ mode: 'LOCKED' }) } |
| 117 | }) |
| 118 | }); |
| 119 | const state = await store.put( |
| 120 | createAutomation({ |
| 121 | id: 'blocked', |
| 122 | ownerId: '123', |
| 123 | steps: [{ callback: 'write:x', key: 'k1' }] |
| 124 | }) |
| 125 | ); |
| 126 | const blocked = await runner.advance(state); |
| 127 | assert.equal(blocked.status, 'paused_kill_switch'); |
| 128 | assert.equal(routed, 0); |
| 129 | }); |
| 130 | test('only owner-approved control can change lock state and unlock is sensitive', async () => { |
| 131 | const calls = []; |
| 132 | const store = { |
| 133 | get: async () => ({ mode: 'NORMAL' }), |
| 134 | set: async (next) => { |
| 135 | calls.push(next); |
| 136 | return next; |
| 137 | } |
| 138 | }; |
| 139 | const killSwitch = new KillSwitch({ store }); |
| 140 | await assert.rejects( |
| 141 | () => killSwitch.lock({ isOwner: false, approved: true }), |
| 142 | /owner/i |
| 143 | ); |
| 144 | await assert.rejects( |
| 145 | () => killSwitch.lock({ isOwner: true, approved: false }), |
| 146 | /approval/i |
| 147 | ); |
| 148 | await killSwitch.lock({ isOwner: true, approved: true }); |
| 149 | await assert.rejects( |
| 150 | () => killSwitch.unlock({ isOwner: true, approved: false }), |
| 151 | /approval/i |
| 152 | ); |
| 153 | await killSwitch.unlock({ isOwner: true, approved: true }); |
| 154 | assert.deepEqual( |
| 155 | calls.map((x) => x.mode), |
| 156 | ['LOCKED', 'NORMAL'] |
| 157 | ); |
| 158 | }); |