sneakoscope 7.3.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -10
- package/crates/sks-core/Cargo.lock +1 -1
- package/crates/sks-core/Cargo.toml +1 -1
- package/dist/cli/codex-app-command.js +1 -1
- package/dist/cli/command-manifest-lite.js +4 -1
- package/dist/cli/command-registry.js +2 -0
- package/dist/cli/install-helpers-codex-lb-chain.js +42 -0
- package/dist/cli/install-helpers-codex-lb-config.js +114 -9
- package/dist/cli/install-helpers-install-support.js +6 -16
- package/dist/cli/install-helpers.js +788 -600
- package/dist/cli/router.js +30 -2
- package/dist/commands/codex-app.js +37 -1
- package/dist/commands/codex-lb.js +491 -300
- package/dist/config/skills-manifest.json +57 -71
- package/dist/core/align/align-route.js +127 -0
- package/dist/core/codex-app/codex-app-fast-ui-repair.js +8 -4
- package/dist/core/codex-app/codex-app-restart.js +83 -0
- package/dist/core/codex-app/codex-app-ui-state-snapshot.js +8 -4
- package/dist/core/codex-app/desktop-routing-snapshot.js +1 -1
- package/dist/core/codex-app/menubar/constants.js +5 -0
- package/dist/core/codex-app/menubar/generation-transaction-journal.js +1 -3
- package/dist/core/codex-app/menubar/installer.js +18 -0
- package/dist/core/codex-app/multi-provider-router.js +22 -10
- package/dist/core/codex-app/openrouter-activate.js +26 -1
- package/dist/core/codex-app.js +118 -26
- package/dist/core/codex-control/codex-app-server-runtime-env.js +86 -0
- package/dist/core/codex-control/codex-app-server-v2-client.js +78 -8
- package/dist/core/codex-control/codex-task-runner.js +2 -2
- package/dist/core/codex-lb/capability-runner.js +204 -0
- package/dist/core/codex-lb/capability-types.js +1 -0
- package/dist/core/codex-lb/codex-lb-env.js +9 -13
- package/dist/core/codex-lb/codex-lb-setup.js +45 -8
- package/dist/core/codex-lb/codex-lb-tool-catalog.js +52 -74
- package/dist/core/codex-lb/codex-lb-tool-output-recovery.js +1 -1
- package/dist/core/codex-lb/desktop-auth-invariant.js +185 -0
- package/dist/core/codex-lb/desktop-bridge/client.js +34 -0
- package/dist/core/codex-lb/desktop-bridge/header-policy.js +106 -0
- package/dist/core/codex-lb/desktop-bridge/http-forward.js +101 -0
- package/dist/core/codex-lb/desktop-bridge/index.js +10 -0
- package/dist/core/codex-lb/desktop-bridge/launchd.js +81 -0
- package/dist/core/codex-lb/desktop-bridge/location-rewrite.js +27 -0
- package/dist/core/codex-lb/desktop-bridge/security.js +274 -0
- package/dist/core/codex-lb/desktop-bridge/server.js +179 -0
- package/dist/core/codex-lb/desktop-bridge/state.js +119 -0
- package/dist/core/codex-lb/desktop-bridge/types.js +16 -0
- package/dist/core/codex-lb/desktop-bridge/websocket-forward.js +151 -0
- package/dist/core/codex-lb/desktop-center-credentials.js +189 -0
- package/dist/core/codex-lb/desktop-controller.js +1410 -0
- package/dist/core/codex-lb/desktop-mode.js +32 -0
- package/dist/core/codex-lb/desktop-real-evidence.js +168 -0
- package/dist/core/codex-lb/desktop-service.js +613 -0
- package/dist/core/codex-lb/legacy-migration.js +575 -0
- package/dist/core/codex-lb/migration-receipt.js +246 -0
- package/dist/core/codex-lb/probes/auxiliary-surfaces-probe.js +60 -0
- package/dist/core/codex-lb/probes/bridge-probe.js +75 -0
- package/dist/core/codex-lb/probes/catalog-probe.js +128 -0
- package/dist/core/codex-lb/probes/computer-use-probe.js +50 -0
- package/dist/core/codex-lb/probes/image-generation-probe.js +47 -0
- package/dist/core/codex-lb/probes/probe-evidence.js +39 -0
- package/dist/core/codex-lb/probes/voice-realtime-probe.js +44 -0
- package/dist/core/codex-lb/trusted-deep-evidence.js +403 -0
- package/dist/core/codex-native/core-skill-manifest.js +22 -6
- package/dist/core/codex-runtime/codex-desktop-config-policy.js +2 -1
- package/dist/core/commands/align-command.js +220 -0
- package/dist/core/commands/image-ux-review-command.js +280 -68
- package/dist/core/commands/naruto-command.js +257 -8
- package/dist/core/commands/ppt-command.js +2 -2
- package/dist/core/commands/telegram-command.js +402 -34
- package/dist/core/commands/triwiki-command.js +11 -1
- package/dist/core/commands/triwiki-graph-command.js +160 -0
- package/dist/core/commands/wiki-command.js +100 -20
- package/dist/core/doctor/skill-legacy-surface.js +1 -3
- package/dist/core/errors/message.js +3 -0
- package/dist/core/evidence/evidence-freshness.js +14 -0
- package/dist/core/feature-fixtures.js +9 -1
- package/dist/core/feature-registry.js +5 -3
- package/dist/core/fsx.js +7 -3
- package/dist/core/hooks-runtime/codex-commit-hooks-selftest.js +82 -0
- package/dist/core/hooks-runtime/context-graph-freshness-preflight.js +113 -0
- package/dist/core/hooks-runtime/hook-context.js +15 -2
- package/dist/core/hooks-runtime/managed-skill-generation-heal.js +46 -0
- package/dist/core/hooks-runtime/naruto-terminal-finalization.js +1 -0
- package/dist/core/hooks-runtime/official-subagent-lifecycle.js +1 -1
- package/dist/core/hooks-runtime/tool-output-quarantine.js +1 -1
- package/dist/core/hooks-runtime.js +33 -89
- package/dist/core/image-ux-review/callout-extraction.js +6 -0
- package/dist/core/image-ux-review/imagegen-adapter.js +64 -23
- package/dist/core/image-ux-review/real-callout-extractor.js +1 -0
- package/dist/core/image-ux-review.js +230 -12
- package/dist/core/imagegen/codex-lb-imagegen-target.js +21 -7
- package/dist/core/imagegen/imagegen-capability.js +10 -4
- package/dist/core/imagegen/require-imagegen.js +29 -5
- package/dist/core/init/skills.js +25 -13
- package/dist/core/init.js +1 -1
- package/dist/core/install/installed-package-smoke.js +157 -4
- package/dist/core/managed-assets/managed-assets-manifest.js +2 -1
- package/dist/core/managed-path-safety.js +8 -10
- package/dist/core/mcp-config/backup.js +2 -4
- package/dist/core/mcp-config/config-reader.js +2 -4
- package/dist/core/mcp-config/scope.js +3 -5
- package/dist/core/naruto/context-graph-advisor-scope.js +242 -0
- package/dist/core/naruto/context-graph-advisor.js +0 -0
- package/dist/core/perf/release-latency-slo.js +12 -6
- package/dist/core/pipeline-internals/runtime-core.js +78 -0
- package/dist/core/pipeline-internals/runtime-gates.js +5 -2
- package/dist/core/policy/latest-version-guidance.js +113 -0
- package/dist/core/ppt.js +8 -8
- package/dist/core/preflight/parallel-preflight-engine.js +1 -1
- package/dist/core/proof/auto-finalize.js +98 -6
- package/dist/core/proof/route-proof-gate.js +12 -1
- package/dist/core/proof/route-proof-policy.js +8 -8
- package/dist/core/release/gate-manifest.js +32 -1
- package/dist/core/release/npm-stage-contract.js +21 -0
- package/dist/core/release/package-size-budget.js +2 -2
- package/dist/core/release/release-gate-contract.js +5 -0
- package/dist/core/release/release-proof-io.js +1 -3
- package/dist/core/release/release-real-contract.js +5 -4
- package/dist/core/release/release-stamp-proof.js +1 -3
- package/dist/core/release/stage-publish.js +27 -0
- package/dist/core/remote/audit-idempotency.js +50 -18
- package/dist/core/remote/codex-public-activity.js +283 -0
- package/dist/core/remote/index.js +1 -0
- package/dist/core/remote/ssh-worker-client.js +4 -1
- package/dist/core/remote/worker.js +206 -27
- package/dist/core/research/research-adversarial-review.js +1 -3
- package/dist/core/research/research-claim-synthesizer.js +1 -3
- package/dist/core/research/research-falsification-runner.js +1 -3
- package/dist/core/research/research-source-evidence.js +1 -3
- package/dist/core/responses-stream.js +65 -19
- package/dist/core/routes/constants.js +1 -1
- package/dist/core/routes/design-policy.js +7 -2
- package/dist/core/routes/dollar-manifest-lite.js +2 -4
- package/dist/core/routes/evidence.js +1 -1
- package/dist/core/routes.js +30 -10
- package/dist/core/safety/command-contract/contracts.js +2 -0
- package/dist/core/safety/command-contract/types.js +1 -1
- package/dist/core/search/context-graph-seeds.js +205 -0
- package/dist/core/search/context.js +0 -0
- package/dist/core/search/provider.js +2 -2
- package/dist/core/secret-redaction.js +6 -0
- package/dist/core/subagents/naruto-help-contract.js +2 -1
- package/dist/core/subagents/naruto-host-credentials.js +161 -0
- package/dist/core/subagents/official-subagent-preparation.js +4 -1
- package/dist/core/subagents/official-subagent-prompt.js +44 -2
- package/dist/core/subagents/official-subagent-runner.js +26 -8
- package/dist/core/subagents/triwiki-attention.js +135 -123
- package/dist/core/telegram/bot-api.js +85 -10
- package/dist/core/telegram/center-snapshot.js +718 -0
- package/dist/core/telegram/config.js +158 -31
- package/dist/core/telegram/hub.js +288 -33
- package/dist/core/telegram/index.js +2 -0
- package/dist/core/telegram/ingress-spool.js +419 -0
- package/dist/core/telegram/ledgers.js +188 -29
- package/dist/core/telegram/messages.js +26 -6
- package/dist/core/telegram/owner-lock.js +10 -7
- package/dist/core/telegram/runtime-projection.js +38 -3
- package/dist/core/telegram/runtime.js +298 -63
- package/dist/core/telegram/service.js +137 -8
- package/dist/core/telegram/setup.js +291 -73
- package/dist/core/text/strings.js +3 -0
- package/dist/core/triwiki/code-pack.js +12 -120
- package/dist/core/triwiki/context-graph/compiler/cache-key.js +277 -0
- package/dist/core/triwiki/context-graph/compiler/extract.js +104 -0
- package/dist/core/triwiki/context-graph/compiler/freshness.js +108 -0
- package/dist/core/triwiki/context-graph/compiler/index.js +237 -0
- package/dist/core/triwiki/context-graph/compiler/merge.js +0 -0
- package/dist/core/triwiki/context-graph/compiler/serialize.js +115 -0
- package/dist/core/triwiki/context-graph/contracts.js +236 -0
- package/dist/core/triwiki/context-graph/extractors/code/builders.js +150 -0
- package/dist/core/triwiki/context-graph/extractors/code/declarations.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/index.js +265 -0
- package/dist/core/triwiki/context-graph/extractors/code/inventory.js +237 -0
- package/dist/core/triwiki/context-graph/extractors/code/module-graph.js +252 -0
- package/dist/core/triwiki/context-graph/extractors/code/modules.js +79 -0
- package/dist/core/triwiki/context-graph/extractors/code/references.js +184 -0
- package/dist/core/triwiki/context-graph/extractors/code/selection.js +100 -0
- package/dist/core/triwiki/context-graph/extractors/code/ts-config.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/types.js +18 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/claims.js +289 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/index.js +54 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proof-index.js +213 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proofs.js +266 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/redaction.js +177 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/shared.js +0 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/sources.js +154 -0
- package/dist/core/triwiki/context-graph/extractors/index.js +7 -0
- package/dist/core/triwiki/context-graph/extractors/topology/commands.js +207 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gate-edges.js +201 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gates.js +182 -0
- package/dist/core/triwiki/context-graph/extractors/topology/globs.js +124 -0
- package/dist/core/triwiki/context-graph/extractors/topology/index.js +92 -0
- package/dist/core/triwiki/context-graph/extractors/topology/routes.js +135 -0
- package/dist/core/triwiki/context-graph/extractors/topology/shared.js +215 -0
- package/dist/core/triwiki/context-graph/graph-index.js +143 -0
- package/dist/core/triwiki/context-graph/ids.js +0 -0
- package/dist/core/triwiki/context-graph/lint/index.js +0 -0
- package/dist/core/triwiki/context-graph/lint/rules.js +232 -0
- package/dist/core/triwiki/context-graph/lint/warnings.js +93 -0
- package/dist/core/triwiki/context-graph/paths.js +116 -0
- package/dist/core/triwiki/context-graph/profiles.js +78 -0
- package/dist/core/triwiki/context-graph/projections/anchors.js +91 -0
- package/dist/core/triwiki/context-graph/projections/attention.js +58 -0
- package/dist/core/triwiki/context-graph/projections/code-pack-workspace.js +62 -0
- package/dist/core/triwiki/context-graph/projections/code-pack.js +144 -0
- package/dist/core/triwiki/context-graph/projections/index.js +7 -0
- package/dist/core/triwiki/context-graph/projections/module-view.js +140 -0
- package/dist/core/triwiki/context-graph/projections/node-summary.js +118 -0
- package/dist/core/triwiki/context-graph/projections/pack-contract.js +6 -0
- package/dist/core/triwiki/context-graph/query/explain.js +0 -0
- package/dist/core/triwiki/context-graph/query/index.js +178 -0
- package/dist/core/triwiki/context-graph/query/load.js +116 -0
- package/dist/core/triwiki/context-graph/query/pack.js +117 -0
- package/dist/core/triwiki/context-graph/query/rank.js +142 -0
- package/dist/core/triwiki/context-graph/query/ranking-config.js +64 -0
- package/dist/core/triwiki/context-graph/query/seeds.js +241 -0
- package/dist/core/triwiki/context-graph/query/snapshot-cache.js +72 -0
- package/dist/core/triwiki/context-graph/query/traverse.js +154 -0
- package/dist/core/triwiki/context-graph/query-types.js +29 -0
- package/dist/core/triwiki/context-graph/store/compile-lock.js +21 -0
- package/dist/core/triwiki/context-graph/store/event-log.js +48 -0
- package/dist/core/triwiki/context-graph/store/fragment-cache.js +85 -0
- package/dist/core/triwiki/context-graph/store/graph-status.js +85 -0
- package/dist/core/triwiki/context-graph/store/snapshot-store.js +155 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-repair.js +115 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-store.js +290 -0
- package/dist/core/triwiki/triwiki-proof-bank-index.js +126 -0
- package/dist/core/triwiki/triwiki-proof-bank.js +7 -1
- package/dist/core/verification/context-graph-affected.js +271 -0
- package/dist/core/version.js +1 -1
- package/dist/native/sks-menubar/Sources/AlertFactory.swift +11 -3
- package/dist/native/sks-menubar/Sources/AppDelegate.swift +9 -0
- package/dist/native/sks-menubar/Sources/ControlCenterWindowController.swift +25 -3
- package/dist/native/sks-menubar/Sources/ControlKit.swift +19 -8
- package/dist/native/sks-menubar/Sources/DiagnosticsViewController.swift +1 -2
- package/dist/native/sks-menubar/Sources/MCPServersViewController.swift +45 -17
- package/dist/native/sks-menubar/Sources/OverviewSummary.swift +162 -0
- package/dist/native/sks-menubar/Sources/OverviewViewController.swift +136 -190
- package/dist/native/sks-menubar/Sources/ProcessClient.swift +107 -11
- package/dist/native/sks-menubar/Sources/ProvidersMultiProvider.swift +5 -1
- package/dist/native/sks-menubar/Sources/ProvidersOpenRouter.swift +16 -4
- package/dist/native/sks-menubar/Sources/ProvidersRoleModels.swift +4 -1
- package/dist/native/sks-menubar/Sources/ProvidersRoutingTruth.swift +131 -0
- package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +288 -341
- package/dist/native/sks-menubar/Sources/RemoteTelegramCenterState.swift +447 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramRendering.swift +484 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramViewController.swift +364 -115
- package/dist/native/sks-menubar/Sources/SettingsViewController.swift +73 -12
- package/dist/native/sks-menubar/Sources/SidebarItem.swift +3 -3
- package/dist/native/sks-menubar/Sources/StatusItemController.swift +13 -13
- package/dist/native/sks-menubar/Sources/TelegramHubSupervisor.swift +469 -0
- package/dist/native/sks-menubar/Sources/UpdatesViewController.swift +1 -6
- package/dist/native/sks-menubar/Tests/AppRuntimeTestSupport.swift +12 -0
- package/dist/native/sks-menubar/Tests/NativeTelegramRegressionRunner.swift +55 -0
- package/dist/native/sks-menubar/Tests/ProcessClientTests.swift +33 -0
- package/dist/native/sks-menubar/Tests/ProvidersViewControllerTests.swift +142 -0
- package/dist/native/sks-menubar/Tests/RemoteTelegramCenterStateTests.swift +56 -0
- package/dist/native/sks-menubar/Tests/TelegramHubSupervisorTests.swift +55 -0
- package/dist/scripts/codex-lb-catalog-passthrough-check.js +120 -0
- package/dist/scripts/codex-lb-desktop-auth-invariant-check.js +169 -0
- package/dist/scripts/codex-lb-desktop-bridge-check.js +394 -0
- package/dist/scripts/codex-lb-desktop-bridge-latency-check.js +196 -0
- package/dist/scripts/codex-lb-desktop-capabilities-check.js +287 -0
- package/dist/scripts/codex-lb-desktop-real-evidence-check.js +123 -0
- package/dist/scripts/codex-lb-fast-mode-truth-check.js +10 -3
- package/dist/scripts/codex-lb-fast-ui-preservation-check.js +81 -40
- package/dist/scripts/codex-lb-gpt56-fast-profile-check.js +99 -37
- package/dist/scripts/context-graph-check.js +191 -0
- package/dist/scripts/doctor-fixes-codex-app-fast-ui-check.js +1 -1
- package/dist/scripts/gate-policy-audit-check.js +1 -1
- package/dist/scripts/helper-dedup-check.js +0 -2
- package/dist/scripts/installed-package-smoke-check.js +4 -1
- package/dist/scripts/latest-version-guidance-check.js +74 -0
- package/dist/scripts/release-metadata-check.js +21 -4
- package/dist/scripts/release-real-check.js +7 -0
- package/dist/scripts/ux-review-imagegen-blackbox-check.js +25 -1
- package/dist/scripts/ux-review-run-wires-imagegen-check.js +9 -1
- package/package.json +8 -3
- package/release-gates.v2.json +176 -1
- package/runtime-required-scripts.json +30 -0
- package/schemas/triwiki/context-graph.schema.json +119 -0
- package/dist/cli/install-helpers-codex-lb-selftest-chain.js +0 -112
- package/dist/cli/install-helpers-codex-lb-selftest.js +0 -481
- package/dist/core/triwiki/code-index-scanner.js +0 -309
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#if canImport(XCTest)
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
final class ProvidersViewControllerTests: XCTestCase {
|
|
5
|
+
func testUnsignedStructuredCapabilityJSONCannotVerify() {
|
|
6
|
+
let fabricated: [String: Any] = [
|
|
7
|
+
"overall": "verified",
|
|
8
|
+
"image_generation": ["state": "verified", "source": "deep_probe"],
|
|
9
|
+
"computer_use": ["state": "verified", "source": "deep_probe"]
|
|
10
|
+
]
|
|
11
|
+
XCTAssertFalse(CapabilityVerificationTruth.deepEvidenceTrusted(in: fabricated))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func testTrustedValidationRequiresExactVerifiedAttestation() {
|
|
15
|
+
let trusted: [String: Any] = [
|
|
16
|
+
"overall": "verified",
|
|
17
|
+
"deep_evidence_validation": [
|
|
18
|
+
"schema": "sks.codex-lb-deep-evidence-validation.v1",
|
|
19
|
+
"state": "verified",
|
|
20
|
+
"trusted": true,
|
|
21
|
+
"blockers": []
|
|
22
|
+
]
|
|
23
|
+
]
|
|
24
|
+
XCTAssertTrue(CapabilityVerificationTruth.deepEvidenceTrusted(in: trusted))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func testStructuredBlockersArePreservedForFailureRendering() {
|
|
28
|
+
let blocked: [String: Any] = [
|
|
29
|
+
"overall": "blocked",
|
|
30
|
+
"image_generation": [
|
|
31
|
+
"state": "blocked",
|
|
32
|
+
"blockers": ["codex_lb_deep_evidence_stale"]
|
|
33
|
+
]
|
|
34
|
+
]
|
|
35
|
+
XCTAssertEqual(
|
|
36
|
+
CapabilityVerificationTruth.blockers(in: blocked),
|
|
37
|
+
["codex_lb_deep_evidence_stale"]
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func testStatusV2BuiltinOpenAISelectionIsChatGPTOauthModeNotLegacyCodexLb() {
|
|
42
|
+
let status: [String: Any] = [
|
|
43
|
+
"schema": "sks.codex-lb-status.v2",
|
|
44
|
+
"ok": true,
|
|
45
|
+
"configured": true,
|
|
46
|
+
"mode": "cli-provider",
|
|
47
|
+
"oauth": [
|
|
48
|
+
"present": true,
|
|
49
|
+
"preserved": true,
|
|
50
|
+
"mode": "chatgpt_oauth"
|
|
51
|
+
],
|
|
52
|
+
"provider": [
|
|
53
|
+
"id": "openai",
|
|
54
|
+
"built_in": true,
|
|
55
|
+
"contract": "codex-lb-cli",
|
|
56
|
+
"contract_ok": true,
|
|
57
|
+
"selected": true
|
|
58
|
+
],
|
|
59
|
+
"bridge": [
|
|
60
|
+
"key_fingerprint": "sha256:fixture"
|
|
61
|
+
]
|
|
62
|
+
]
|
|
63
|
+
let snapshot = ProviderRoutingTruth.snapshot(from: status)
|
|
64
|
+
XCTAssertEqual(snapshot.mode, "cli-provider")
|
|
65
|
+
XCTAssertFalse(snapshot.desktopFullRouting)
|
|
66
|
+
XCTAssertFalse(snapshot.legacyCodexLbSelected)
|
|
67
|
+
XCTAssertTrue(snapshot.chatgptOauthPresent)
|
|
68
|
+
XCTAssertTrue(snapshot.cliProviderStored)
|
|
69
|
+
XCTAssertTrue(snapshot.cliCredentialsConfigured)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func testStatusV2DesktopBridgeModeIsSelectableCodexLb() {
|
|
73
|
+
let status: [String: Any] = [
|
|
74
|
+
"schema": "sks.codex-lb-status.v2",
|
|
75
|
+
"configured": true,
|
|
76
|
+
"mode": "desktop-native-bridge",
|
|
77
|
+
"oauth": [
|
|
78
|
+
"present": true,
|
|
79
|
+
"mode": "chatgpt_oauth"
|
|
80
|
+
],
|
|
81
|
+
"provider": [
|
|
82
|
+
"id": "openai",
|
|
83
|
+
"selected": true,
|
|
84
|
+
"contract": "builtin-openai"
|
|
85
|
+
]
|
|
86
|
+
]
|
|
87
|
+
let snapshot = ProviderRoutingTruth.snapshot(from: status)
|
|
88
|
+
XCTAssertTrue(snapshot.desktopFullRouting)
|
|
89
|
+
XCTAssertFalse(snapshot.legacyCodexLbSelected)
|
|
90
|
+
XCTAssertTrue(snapshot.chatgptOauthPresent)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
func testStatusV2DetectsLegacyCodexLbWhenBuiltinProviderNotSelected() {
|
|
94
|
+
let status: [String: Any] = [
|
|
95
|
+
"mode": "cli-provider",
|
|
96
|
+
"configured": true,
|
|
97
|
+
"oauth": ["present": false, "mode": "openai_api_key"],
|
|
98
|
+
"provider": [
|
|
99
|
+
"id": "openai",
|
|
100
|
+
"selected": false,
|
|
101
|
+
"contract": "codex-lb-cli"
|
|
102
|
+
]
|
|
103
|
+
]
|
|
104
|
+
let snapshot = ProviderRoutingTruth.snapshot(from: status)
|
|
105
|
+
XCTAssertTrue(snapshot.legacyCodexLbSelected)
|
|
106
|
+
XCTAssertFalse(snapshot.chatgptOauthPresent)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
func testStatusV2DoesNotTreatNestedBridgeStatusAsLegacyDestructive() {
|
|
110
|
+
let status: [String: Any] = [
|
|
111
|
+
"mode": "cli-provider",
|
|
112
|
+
"configured": true,
|
|
113
|
+
"oauth": ["present": true, "mode": "chatgpt_oauth"],
|
|
114
|
+
"provider": ["id": "openai", "selected": true],
|
|
115
|
+
"bridge": ["status": "settings_missing"]
|
|
116
|
+
]
|
|
117
|
+
let snapshot = ProviderRoutingTruth.snapshot(from: status)
|
|
118
|
+
XCTAssertFalse(snapshot.legacyDestructive)
|
|
119
|
+
XCTAssertFalse(snapshot.legacyCodexLbSelected)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
func testDisabledChatGPTOauthModeIsNotTreatedAsLegacyCodexLbSelection() {
|
|
123
|
+
let status: [String: Any] = [
|
|
124
|
+
"schema": "sks.codex-lb-status.v2",
|
|
125
|
+
"mode": "disabled",
|
|
126
|
+
"configured": false,
|
|
127
|
+
"oauth": ["present": true, "mode": "chatgpt_oauth"],
|
|
128
|
+
"provider": [
|
|
129
|
+
"id": "openai",
|
|
130
|
+
"selected": true,
|
|
131
|
+
"built_in": true,
|
|
132
|
+
"contract": "builtin-openai"
|
|
133
|
+
]
|
|
134
|
+
]
|
|
135
|
+
let snapshot = ProviderRoutingTruth.snapshot(from: status)
|
|
136
|
+
XCTAssertEqual(snapshot.mode, "disabled")
|
|
137
|
+
XCTAssertFalse(snapshot.desktopFullRouting)
|
|
138
|
+
XCTAssertFalse(snapshot.legacyCodexLbSelected)
|
|
139
|
+
XCTAssertTrue(snapshot.chatgptOauthPresent)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
#endif
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#if canImport(XCTest)
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
final class RemoteTelegramCenterStateTests: XCTestCase {
|
|
5
|
+
func testTimeoutFailureIsActionableAndDoesNotClaimStateWasCleared() {
|
|
6
|
+
let result = ProcessResult(
|
|
7
|
+
code: -2,
|
|
8
|
+
output: ProcessClient.nativeFailureOutput("native_process_timeout"),
|
|
9
|
+
truncated: false,
|
|
10
|
+
timedOut: true,
|
|
11
|
+
emptyOutput: false
|
|
12
|
+
)
|
|
13
|
+
let message = RemoteTelegramViewController.telegramStatusFailureMessage(result)
|
|
14
|
+
XCTAssertTrue(message.contains("bounded native deadline"))
|
|
15
|
+
XCTAssertTrue(message.contains("api.telegram.org"))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func testEmptyStatusJSONHasStableRetryGuidance() {
|
|
19
|
+
let result = ProcessResult(
|
|
20
|
+
code: -3,
|
|
21
|
+
output: ProcessClient.nativeFailureOutput("native_process_empty_output"),
|
|
22
|
+
truncated: false,
|
|
23
|
+
timedOut: false,
|
|
24
|
+
emptyOutput: true
|
|
25
|
+
)
|
|
26
|
+
XCTAssertEqual(
|
|
27
|
+
RemoteTelegramViewController.telegramStatusFailureMessage(result),
|
|
28
|
+
"Telegram status returned no JSON. Retry, then open Diagnostics if the CLI remains unavailable."
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func testLiveSourceChangeDuringReadRequestsOnlyOneImmediateCatchUp() {
|
|
33
|
+
XCTAssertTrue(
|
|
34
|
+
RemoteTelegramViewController.shouldRequestImmediateLiveCatchUp(
|
|
35
|
+
requestSignature: "source-v1",
|
|
36
|
+
completionSignature: "source-v2",
|
|
37
|
+
wasCatchUp: false
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
XCTAssertFalse(
|
|
41
|
+
RemoteTelegramViewController.shouldRequestImmediateLiveCatchUp(
|
|
42
|
+
requestSignature: "source-v2",
|
|
43
|
+
completionSignature: "source-v3",
|
|
44
|
+
wasCatchUp: true
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
XCTAssertFalse(
|
|
48
|
+
RemoteTelegramViewController.shouldRequestImmediateLiveCatchUp(
|
|
49
|
+
requestSignature: "source-v2",
|
|
50
|
+
completionSignature: "source-v2",
|
|
51
|
+
wasCatchUp: false
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
#endif
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#if canImport(XCTest)
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
final class TelegramHubSupervisorTests: XCTestCase {
|
|
5
|
+
func testOnlyVerifiedDirectServiceQualifiesForPredecessorHandoff() {
|
|
6
|
+
let verified = TelegramHubSupervisor.serviceSnapshot(from: """
|
|
7
|
+
{"schema":"sks.telegram-hub-service.v1","running":true,"receive_ready":false,"mode":"direct","pid":4242}
|
|
8
|
+
""")
|
|
9
|
+
XCTAssertEqual(verified?.verifiedDirectPID, 4242)
|
|
10
|
+
|
|
11
|
+
let foreign = TelegramHubSupervisor.serviceSnapshot(from: """
|
|
12
|
+
{"schema":"sks.telegram-hub-service.v1","running":false,"receive_ready":false,"mode":null,"pid":null}
|
|
13
|
+
""")
|
|
14
|
+
XCTAssertNil(foreign?.verifiedDirectPID)
|
|
15
|
+
|
|
16
|
+
let launchAgent = TelegramHubSupervisor.serviceSnapshot(from: """
|
|
17
|
+
{"schema":"sks.telegram-hub-service.v1","running":true,"receive_ready":true,"mode":"launch_agent","pid":5252}
|
|
18
|
+
""")
|
|
19
|
+
XCTAssertNil(launchAgent?.verifiedDirectPID)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
func testOwnerAndNetworkStartupFailuresRetryButConfigurationFailureDoesNot() {
|
|
23
|
+
XCTAssertTrue(TelegramHubSupervisor.retryableStartupFailure("telegram_hub_owner_conflict"))
|
|
24
|
+
XCTAssertTrue(TelegramHubSupervisor.retryableStartupFailure("telegram_hub_network_unavailable"))
|
|
25
|
+
XCTAssertTrue(TelegramHubSupervisor.retryableStartupFailure("telegram_hub_startup_timeout"))
|
|
26
|
+
XCTAssertFalse(TelegramHubSupervisor.retryableStartupFailure("telegram_hub_startup_failed"))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func testOwnerConflictMessageStatesForeignOwnerWasNotTerminated() {
|
|
30
|
+
XCTAssertEqual(
|
|
31
|
+
TelegramHubSupervisor.startupFailureMessage(for: "telegram_hub_owner_conflict"),
|
|
32
|
+
"Another Telegram Hub still owns this bot. Stop that Hub, then retry. Center did not terminate the other owner."
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func testStartupOutputClassificationIsStable() {
|
|
37
|
+
XCTAssertEqual(
|
|
38
|
+
TelegramHubSupervisor.startupFailureReason(
|
|
39
|
+
output: #"{"error":"telegram_owner_conflict"}"#
|
|
40
|
+
),
|
|
41
|
+
"telegram_hub_owner_conflict"
|
|
42
|
+
)
|
|
43
|
+
XCTAssertEqual(
|
|
44
|
+
TelegramHubSupervisor.startupFailureReason(
|
|
45
|
+
output: #"{"stopped_reason":"telegram_poll_failed","error":"telegram_api_timeout"}"#
|
|
46
|
+
),
|
|
47
|
+
"telegram_hub_network_unavailable"
|
|
48
|
+
)
|
|
49
|
+
XCTAssertEqual(
|
|
50
|
+
TelegramHubSupervisor.startupFailureReason(output: ""),
|
|
51
|
+
"telegram_hub_empty_startup_output"
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
#endif
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import http, {} from 'node:http';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { ensureCodexLbToolCatalog, normalizeCodexLbToolCatalog } from '../core/codex-lb/codex-lb-tool-catalog.js';
|
|
7
|
+
import { assertGate, emitGate } from './gate-lib.js';
|
|
8
|
+
const gatewayKey = 'catalog-gate-secret';
|
|
9
|
+
const sensitiveEcho = 'Bearer catalog-gate-secret-must-not-persist';
|
|
10
|
+
const model = {
|
|
11
|
+
id: 'future-codex-model',
|
|
12
|
+
display_name: 'Future Codex',
|
|
13
|
+
supported_reasoning_levels: [{ effort: 'high', future_effort_field: true }],
|
|
14
|
+
truncation_policy: { mode: 'tokens', future_policy_field: 17 },
|
|
15
|
+
use_responses_lite: true,
|
|
16
|
+
future_unknown_field: {
|
|
17
|
+
nested: ['preserve', { exactly: true }]
|
|
18
|
+
},
|
|
19
|
+
debug_echoed_authorization: sensitiveEcho
|
|
20
|
+
};
|
|
21
|
+
const payload = { models: [model] };
|
|
22
|
+
const normalized = normalizeCodexLbToolCatalog(payload);
|
|
23
|
+
const normalizedRow = normalized.catalog.models[0];
|
|
24
|
+
let observedAuthorization = '';
|
|
25
|
+
let observedPath = '';
|
|
26
|
+
const upstream = http.createServer((request, response) => {
|
|
27
|
+
observedAuthorization = String(request.headers.authorization || '');
|
|
28
|
+
observedPath = String(request.url || '');
|
|
29
|
+
response.writeHead(200, {
|
|
30
|
+
'content-type': 'application/json',
|
|
31
|
+
etag: '"catalog-gate-v2"'
|
|
32
|
+
});
|
|
33
|
+
response.end(JSON.stringify(payload));
|
|
34
|
+
});
|
|
35
|
+
const upstreamPort = await listen(upstream);
|
|
36
|
+
const temporaryRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'sks-codex-lb-catalog-gate-'));
|
|
37
|
+
let ensured = null;
|
|
38
|
+
let persisted = null;
|
|
39
|
+
let metadata = null;
|
|
40
|
+
try {
|
|
41
|
+
const home = path.join(temporaryRoot, 'home');
|
|
42
|
+
const codexHome = path.join(home, '.codex');
|
|
43
|
+
await fs.mkdir(codexHome, { recursive: true });
|
|
44
|
+
ensured = await ensureCodexLbToolCatalog({
|
|
45
|
+
codexHome,
|
|
46
|
+
baseUrl: `http://127.0.0.1:${upstreamPort}/backend-api/codex`,
|
|
47
|
+
apiKey: gatewayKey,
|
|
48
|
+
clientVersion: '0.145.0'
|
|
49
|
+
});
|
|
50
|
+
if (ensured.ok) {
|
|
51
|
+
persisted = JSON.parse(await fs.readFile(ensured.path, 'utf8'));
|
|
52
|
+
metadata = JSON.parse(await fs.readFile(`${ensured.path}.meta.json`, 'utf8'));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
await close(upstream);
|
|
57
|
+
await fs.rm(temporaryRoot, { recursive: true, force: true });
|
|
58
|
+
}
|
|
59
|
+
const persistedRow = Array.isArray(persisted?.models)
|
|
60
|
+
? persisted.models[0]
|
|
61
|
+
: undefined;
|
|
62
|
+
const idToSlug = normalized.ok === true
|
|
63
|
+
&& normalizedRow?.id === model.id
|
|
64
|
+
&& normalizedRow?.slug === model.id;
|
|
65
|
+
const unknownFieldPassthrough = JSON.stringify(normalizedRow?.future_unknown_field) === JSON.stringify(model.future_unknown_field)
|
|
66
|
+
&& JSON.stringify(persistedRow?.future_unknown_field) === JSON.stringify(model.future_unknown_field);
|
|
67
|
+
const fullResponses = normalized.tools_transport === 'full_responses'
|
|
68
|
+
&& normalizedRow?.use_responses_lite === false
|
|
69
|
+
&& persistedRow?.use_responses_lite === false;
|
|
70
|
+
const secretSafe = normalizedRow?.debug_echoed_authorization === undefined
|
|
71
|
+
&& persistedRow?.debug_echoed_authorization === undefined
|
|
72
|
+
&& !JSON.stringify(persisted || {}).includes(gatewayKey)
|
|
73
|
+
&& !JSON.stringify(persisted || {}).includes(sensitiveEcho);
|
|
74
|
+
const fetchedAndBound = ensured?.ok === true
|
|
75
|
+
&& ensured.status === 'repaired'
|
|
76
|
+
&& ensured.identity_verified === true
|
|
77
|
+
&& observedAuthorization === `Bearer ${gatewayKey}`
|
|
78
|
+
&& observedPath === '/backend-api/codex/models'
|
|
79
|
+
&& metadata?.identity?.contract === 'codex-model-catalog-pass-through.v2'
|
|
80
|
+
&& metadata?.unknown_fields_preserved === true
|
|
81
|
+
&& metadata?.upstream_etag === '"catalog-gate-v2"';
|
|
82
|
+
const report = {
|
|
83
|
+
schema: 'sks.codex-lb-catalog-passthrough-check.v1',
|
|
84
|
+
ok: idToSlug && unknownFieldPassthrough && fullResponses && secretSafe && fetchedAndBound,
|
|
85
|
+
id_to_slug: idToSlug,
|
|
86
|
+
unknown_field_passthrough: unknownFieldPassthrough,
|
|
87
|
+
full_responses: fullResponses,
|
|
88
|
+
secret_safe: secretSafe,
|
|
89
|
+
localhost_fetch_verified: fetchedAndBound,
|
|
90
|
+
contract: normalized.contract,
|
|
91
|
+
blockers: [
|
|
92
|
+
...(idToSlug ? [] : ['catalog_id_to_slug_failed']),
|
|
93
|
+
...(unknownFieldPassthrough ? [] : ['catalog_unknown_field_changed']),
|
|
94
|
+
...(fullResponses ? [] : ['catalog_full_responses_not_enforced']),
|
|
95
|
+
...(secretSafe ? [] : ['catalog_secret_persisted']),
|
|
96
|
+
...(fetchedAndBound ? [] : ['catalog_localhost_fetch_unverified'])
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
assertGate(report.ok, 'codex-lb catalog pass-through gate failed', report);
|
|
100
|
+
emitGate('codex-lb:catalog-passthrough', {
|
|
101
|
+
contract: report.contract,
|
|
102
|
+
id_to_slug: report.id_to_slug,
|
|
103
|
+
unknown_field_passthrough: report.unknown_field_passthrough,
|
|
104
|
+
full_responses: report.full_responses,
|
|
105
|
+
localhost_fetch_verified: report.localhost_fetch_verified
|
|
106
|
+
});
|
|
107
|
+
async function listen(server) {
|
|
108
|
+
await new Promise((resolve, reject) => {
|
|
109
|
+
server.once('error', reject);
|
|
110
|
+
server.listen(0, '127.0.0.1', resolve);
|
|
111
|
+
});
|
|
112
|
+
return server.address().port;
|
|
113
|
+
}
|
|
114
|
+
async function close(server) {
|
|
115
|
+
if (!server.listening)
|
|
116
|
+
return;
|
|
117
|
+
await new Promise((resolve, reject) => {
|
|
118
|
+
server.close((error) => error ? reject(error) : resolve());
|
|
119
|
+
});
|
|
120
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { configureCodexLbDesktopRouting } from '../cli/install-helpers.js';
|
|
6
|
+
import { assertDesktopAuthUnchangedBySks, captureCodexAuthSnapshot } from '../core/codex-lb/desktop-auth-invariant.js';
|
|
7
|
+
import { safeWriteCodexConfigToml } from '../core/codex-runtime/codex-desktop-config-policy.js';
|
|
8
|
+
import { assertGate, emitGate } from './gate-lib.js';
|
|
9
|
+
const temporaryRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'sks-codex-lb-desktop-auth-gate-'));
|
|
10
|
+
let report;
|
|
11
|
+
try {
|
|
12
|
+
report = await runCheck(temporaryRoot);
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
await fs.rm(temporaryRoot, { recursive: true, force: true });
|
|
16
|
+
}
|
|
17
|
+
assertGate(report.ok, 'codex-lb Desktop auth invariant gate failed', report);
|
|
18
|
+
emitGate('codex-lb:desktop-auth-invariant', {
|
|
19
|
+
auth_byte_invariant: report.auth_byte_invariant,
|
|
20
|
+
auth_invariant_rollback: report.auth_invariant_rollback,
|
|
21
|
+
conflict_rejected_without_mutation: report.conflict_rejected_without_mutation,
|
|
22
|
+
rollback_conflict_preserved: report.rollback_conflict_preserved
|
|
23
|
+
});
|
|
24
|
+
async function runCheck(root) {
|
|
25
|
+
const home = path.join(root, 'home');
|
|
26
|
+
const codexHome = path.join(home, '.codex');
|
|
27
|
+
const configPath = path.join(codexHome, 'config.toml');
|
|
28
|
+
const authPath = path.join(codexHome, 'auth.json');
|
|
29
|
+
await fs.mkdir(codexHome, { recursive: true });
|
|
30
|
+
const initialConfig = [
|
|
31
|
+
'model = "user-owned-model"',
|
|
32
|
+
'model_reasoning_effort = "high"',
|
|
33
|
+
'service_tier = "standard"',
|
|
34
|
+
'',
|
|
35
|
+
'[features]',
|
|
36
|
+
'fast_mode = false',
|
|
37
|
+
''
|
|
38
|
+
].join('\n');
|
|
39
|
+
const authBytes = Buffer.from([
|
|
40
|
+
'{',
|
|
41
|
+
' "auth_mode": "chatgpt",',
|
|
42
|
+
' "account_id": "acct-auth-gate",',
|
|
43
|
+
' "tokens": {',
|
|
44
|
+
' "access_token": "desktop-oauth-access",',
|
|
45
|
+
' "refresh_token": "desktop-oauth-refresh"',
|
|
46
|
+
' }',
|
|
47
|
+
'}',
|
|
48
|
+
''
|
|
49
|
+
].join('\n'));
|
|
50
|
+
await fs.writeFile(configPath, initialConfig, { mode: 0o600 });
|
|
51
|
+
await fs.writeFile(authPath, authBytes, { mode: 0o600 });
|
|
52
|
+
const before = await captureCodexAuthSnapshot({ home });
|
|
53
|
+
const configured = await configureCodexLbDesktopRouting({
|
|
54
|
+
mode: 'desktop-native-bridge',
|
|
55
|
+
home,
|
|
56
|
+
bridgeBaseUrl: 'http://127.0.0.1:52145/backend-api/codex',
|
|
57
|
+
remoteBaseUrl: 'https://lb.example.test/backend-api/codex',
|
|
58
|
+
gatewayAuthTransport: 'x-codex-lb-api-key'
|
|
59
|
+
});
|
|
60
|
+
const after = await captureCodexAuthSnapshot({ home });
|
|
61
|
+
await assertDesktopAuthUnchangedBySks(before, after);
|
|
62
|
+
const authAfterBytes = await fs.readFile(authPath);
|
|
63
|
+
const configuredText = await fs.readFile(configPath, 'utf8');
|
|
64
|
+
const conflictConfigPath = path.join(codexHome, 'conflict-config.toml');
|
|
65
|
+
const conflictConfig = [
|
|
66
|
+
'model_provider = "user-provider"',
|
|
67
|
+
'',
|
|
68
|
+
'[model_providers.user-provider]',
|
|
69
|
+
'name = "user-provider"',
|
|
70
|
+
'base_url = "https://user.example.test/v1"',
|
|
71
|
+
'wire_api = "responses"',
|
|
72
|
+
''
|
|
73
|
+
].join('\n');
|
|
74
|
+
await fs.writeFile(conflictConfigPath, conflictConfig, { mode: 0o600 });
|
|
75
|
+
const conflictBeforeAuth = await fs.readFile(authPath);
|
|
76
|
+
const conflict = await configureCodexLbDesktopRouting({
|
|
77
|
+
mode: 'desktop-native-bridge',
|
|
78
|
+
home,
|
|
79
|
+
configPath: conflictConfigPath,
|
|
80
|
+
authPath,
|
|
81
|
+
bridgeBaseUrl: 'http://127.0.0.1:52145/backend-api/codex',
|
|
82
|
+
remoteBaseUrl: 'https://lb.example.test/backend-api/codex',
|
|
83
|
+
gatewayAuthTransport: 'x-codex-lb-api-key'
|
|
84
|
+
});
|
|
85
|
+
const conflictAfterAuth = await fs.readFile(authPath);
|
|
86
|
+
const conflictAfterConfig = await fs.readFile(conflictConfigPath, 'utf8');
|
|
87
|
+
const rollbackHome = path.join(root, 'rollback-home');
|
|
88
|
+
const rollbackCodexHome = path.join(rollbackHome, '.codex');
|
|
89
|
+
const rollbackConfigPath = path.join(rollbackCodexHome, 'config.toml');
|
|
90
|
+
const rollbackAuthPath = path.join(rollbackCodexHome, 'auth.json');
|
|
91
|
+
const rollbackInitialConfig = 'service_tier = "standard"\n';
|
|
92
|
+
const rollbackInitialAuth = '{"auth_mode":"chatgpt","account_id":"acct-rollback","tokens":{"access_token":"before"}}\n';
|
|
93
|
+
const rollbackRotatedAuth = '{"auth_mode":"chatgpt","account_id":"acct-rollback","tokens":{"access_token":"after"}}\n';
|
|
94
|
+
await fs.mkdir(rollbackCodexHome, { recursive: true });
|
|
95
|
+
await fs.writeFile(rollbackConfigPath, rollbackInitialConfig, { mode: 0o600 });
|
|
96
|
+
await fs.writeFile(rollbackAuthPath, rollbackInitialAuth, { mode: 0o600 });
|
|
97
|
+
const originalReadFile = fs.readFile.bind(fs);
|
|
98
|
+
const originalWriteFile = fs.writeFile.bind(fs);
|
|
99
|
+
let rollbackAuthReads = 0;
|
|
100
|
+
fs.readFile = async (file, ...args) => {
|
|
101
|
+
if (path.resolve(String(file)) === path.resolve(rollbackAuthPath)) {
|
|
102
|
+
rollbackAuthReads += 1;
|
|
103
|
+
if (rollbackAuthReads === 2) {
|
|
104
|
+
await originalWriteFile(rollbackAuthPath, rollbackRotatedAuth, { mode: 0o600 });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return originalReadFile(file, ...args);
|
|
108
|
+
};
|
|
109
|
+
let invariantRollback;
|
|
110
|
+
try {
|
|
111
|
+
invariantRollback = await configureCodexLbDesktopRouting({
|
|
112
|
+
mode: 'desktop-native-bridge',
|
|
113
|
+
home: rollbackHome,
|
|
114
|
+
bridgeBaseUrl: 'http://127.0.0.1:52146/backend-api/codex',
|
|
115
|
+
remoteBaseUrl: 'https://lb.example.test/backend-api/codex',
|
|
116
|
+
gatewayAuthTransport: 'x-codex-lb-api-key'
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
;
|
|
121
|
+
fs.readFile = originalReadFile;
|
|
122
|
+
fs.writeFile = originalWriteFile;
|
|
123
|
+
}
|
|
124
|
+
const invariantRollbackConfig = await fs.readFile(rollbackConfigPath, 'utf8');
|
|
125
|
+
const invariantRollbackAuth = await fs.readFile(rollbackAuthPath, 'utf8');
|
|
126
|
+
const concurrentUserEdit = `${configuredText.trimEnd()}\n# concurrent user edit retained\n`;
|
|
127
|
+
await fs.writeFile(configPath, concurrentUserEdit, { mode: 0o600 });
|
|
128
|
+
const rollback = await safeWriteCodexConfigToml(configPath, configuredText, initialConfig, 'codex-lb-desktop-routing-auth-invariant-rollback-gate', { verifyUnchangedBeforeWrite: true });
|
|
129
|
+
const afterRollbackAttempt = await fs.readFile(configPath, 'utf8');
|
|
130
|
+
const authByteInvariant = configured.ok === true
|
|
131
|
+
&& configured.oauth_preserved === true
|
|
132
|
+
&& configured.auth_mutated === false
|
|
133
|
+
&& before.sha256 !== null
|
|
134
|
+
&& before.sha256 === after.sha256
|
|
135
|
+
&& authAfterBytes.equals(authBytes);
|
|
136
|
+
const conflictRejectedWithoutMutation = conflict.ok === false
|
|
137
|
+
&& conflict.status === 'failed'
|
|
138
|
+
&& conflict.blockers.includes('desktop_config_conflict')
|
|
139
|
+
&& conflictAfterConfig === conflictConfig
|
|
140
|
+
&& conflictAfterAuth.equals(conflictBeforeAuth);
|
|
141
|
+
const authInvariantRollback = invariantRollback.ok === false
|
|
142
|
+
&& invariantRollback.blockers.includes('desktop_auth_byte_invariant_failed')
|
|
143
|
+
&& invariantRollback.rollback?.config_restored === true
|
|
144
|
+
&& invariantRollbackConfig === rollbackInitialConfig
|
|
145
|
+
&& invariantRollbackAuth === rollbackRotatedAuth;
|
|
146
|
+
const rollbackConflictPreserved = rollback.ok === false
|
|
147
|
+
&& rollback.status === 'concurrent_change_detected'
|
|
148
|
+
&& afterRollbackAttempt === concurrentUserEdit;
|
|
149
|
+
return {
|
|
150
|
+
schema: 'sks.codex-lb-desktop-auth-invariant-check.v1',
|
|
151
|
+
ok: authByteInvariant
|
|
152
|
+
&& authInvariantRollback
|
|
153
|
+
&& conflictRejectedWithoutMutation
|
|
154
|
+
&& rollbackConflictPreserved,
|
|
155
|
+
auth_byte_invariant: authByteInvariant,
|
|
156
|
+
auth_invariant_rollback: authInvariantRollback,
|
|
157
|
+
conflict_rejected_without_mutation: conflictRejectedWithoutMutation,
|
|
158
|
+
rollback_conflict_preserved: rollbackConflictPreserved,
|
|
159
|
+
routing_status: configured.status,
|
|
160
|
+
conflict_status: conflict.status,
|
|
161
|
+
rollback_status: rollback.status,
|
|
162
|
+
blockers: [
|
|
163
|
+
...(authByteInvariant ? [] : ['desktop_auth_bytes_changed']),
|
|
164
|
+
...(authInvariantRollback ? [] : ['desktop_auth_invariant_rollback_failed']),
|
|
165
|
+
...(conflictRejectedWithoutMutation ? [] : ['desktop_config_conflict_mutated_state']),
|
|
166
|
+
...(rollbackConflictPreserved ? [] : ['desktop_rollback_overwrote_concurrent_edit'])
|
|
167
|
+
]
|
|
168
|
+
};
|
|
169
|
+
}
|