{"slug":"business/OPTION_B_BRANCH_DIVERGENCE_AUDIT","title":"OPTION B BRANCH DIVERGENCE AUDIT","section":"business","sectionLabel":"Business","status":"unclassified","type":"document","path":"business/OPTION_B_BRANCH_DIVERGENCE_AUDIT.mdx","bytes":11209,"description":null,"updated":null,"source":"integratewise/Integratewise-docs-wiki","content":"\n> **Tier C — Historical.** This document is a point-in-time snapshot preserved for reference. For current architecture, see [CANONICAL_PLATFORM_ARCHITECTURE.md](../architecture/CANONICAL_PLATFORM_ARCHITECTURE.md).\n\n**Generated**: 2025-07-11  \n**Audit Scope**: Gateway/Connector Service-Binding Decoupling (Wave 0) vs. `origin/main` Restructure\n\n---\n\n## 1. COMMIT LINEAGE SNAPSHOT\n\n| Ref                    | SHA        | Description                                                                         |\n| ---------------------- | ---------- | ----------------------------------------------------------------------------------- |\n| **local `main` HEAD**  | `351e95d9` | Merge PR #59 — identical to `origin/main`                                           |\n| **`origin/main` HEAD** | `351e95d9` | Merge PR #59 (recovery/v1-clean-main)                                               |\n| **Work Commit**        | `afbdb538` | `OPTION B WAVE 0 COMPLETION: Gateway decoupling complete with service bindings`     |\n| **Checkpoint Commit**  | `cc6d3eda` | `checkpoint: pre-Option B working tree restructure`                                 |\n| **Refactor Commit**    | `1d058bf2` | `refactor: remove archive and stale content, add workspace pages and twin features` |\n| **Merge-Base**         | `db9b3b4e` | `feat: merge all 4 source zips by app and department`                               |\n\n### Commit Count Since Merge-Base\n\n- **`origin/main`**: 2 commits (`cdd2a4af`, `351e95d9`)\n- **Work Branch (local only)**: 3 commits (`afbdb538`, `cc6d3eda`, `1d058bf2`)\n- **`gateway-decoupling-complete` (remote)**: Reset to `origin/main` — **work not present on remote branch**\n\n---\n\n## 2. PATH-LEVEL DIVERGENCE ANALYSIS\n\n### 2.1 The 11 Files Modified by Gateway/Connector Decoupling (Commit `afbdb538`)\n\n| #   | Path                                          | Exists on `origin/main` | Changed on `origin/main` since merge-base | Changed on Work Branch | Conflict Risk | Recommended Replay Method    |\n| --- | --------------------------------------------- | ----------------------- | ----------------------------------------- | ---------------------- | ------------- | ---------------------------- |\n| 1   | `OPTION_B_WAVE0_LOG.md`                       | ❌ No (new)             | N/A                                       | ✅ Created             | **None**      | Clean cherry-pick (new file) |\n| 2   | `services/connector/src/connector.test.ts`    | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n| 3   | `services/connector/src/index.ts`             | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n| 4   | `services/connector/wrangler.toml`            | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n| 5   | `services/gateway/src/index.ts`               | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n| 6   | `services/gateway/wrangler.toml`              | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n| 7   | `services/loader/src/index.ts`                | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n| 8   | `services/loader/src/lib/nango.ts`            | ✅ Yes                  | ❌ No                                     | ✅ Created             | **None**      | Clean cherry-pick (new file) |\n| 9   | `services/loader/src/lib/token-refresh.ts`    | ✅ Yes                  | ❌ No                                     | ✅ Created             | **None**      | Clean cherry-pick (new file) |\n| 10  | `services/mcp-connector/src/lib/oauth-jwt.ts` | ✅ Yes                  | ❌ No                                     | ✅ Created             | **None**      | Clean cherry-pick (new file) |\n| 11  | `services/mcp-connector/src/oauth.test.ts`    | ✅ Yes                  | ❌ No                                     | ✅ Modified            | **None**      | Clean cherry-pick            |\n\n**Summary**: **All 11 files are unchanged on `origin/main` since the merge-base `db9b3b4e`**. Zero content conflicts expected.\n\n---\n\n## 3. SERVICE BINDING TOPOLOGY VALIDATION\n\n### 3.1 Bindings Introduced by Work Commit\n\n| Binding   | Target Service | Target Worker Name            | Exists on `origin/main`                       |\n| --------- | -------------- | ----------------------------- | --------------------------------------------- |\n| `ADMIN`   | Admin          | `integratewise-admin`         | ✅ Service exists (`services/admin/`)         |\n| `BILLING` | Billing        | `integratewise-billing`       | ✅ Service exists (`services/billing/`)       |\n| `TENANTS` | Tenants        | `integratewise-tenants`       | ✅ Service exists (`services/tenants/`)       |\n| `LOADER`  | Loader         | `integratewise-loader`        | ✅ Service exists (`services/loader/`)        |\n| `MCP`     | MCP Connector  | `integratewise-mcp-connector` | ✅ Service exists (`services/mcp-connector/`) |\n| `STORE`   | Store          | `integratewise-store`         | ✅ Service exists (`services/store/`)         |\n\n### 3.2 Binding Name Conflicts on `origin/main`\n\n| Binding   | Defined on `origin/main` (gateway) | Defined on `origin/main` (connector) | Conflict? |\n| --------- | ---------------------------------- | ------------------------------------ | --------- |\n| `ADMIN`   | ❌ No                              | N/A                                  | No        |\n| `BILLING` | ❌ No                              | N/A                                  | No        |\n| `TENANTS` | ❌ No                              | N/A                                  | No        |\n| `LOADER`  | N/A                                | ❌ No                                | No        |\n| `MCP`     | ❌ No (only in `[env.test]`)       | ❌ No (commented in default)         | No        |\n| `STORE`   | N/A                                | ❌ No                                | No        |\n\n**Verdict**: No binding name conflicts. All six bindings are new additions that don't collide with existing bindings on `origin/main`.\n\n### 3.3 Service Deployment Names Verification\n\nAll six target worker names (`integratewise-admin`, `integratewise-billing`, `integratewise-tenants`, `integratewise-loader`, `integratewise-mcp-connector`, `integratewise-store`) correspond to actual service directories on `origin/main`. The Cloudflare Worker deployment names match the service binding `service = **service** values.\n\n---\n\n## 4. REPLAY FEASIBILITY MATRIX\n\n| Factor                    | Assessment                                                                                             |\n| ------------------------- | ------------------------------------------------------------------------------------------------------ |\n| **Content overlap**       | None — zero files modified on `origin/main` since merge-base                                           |\n| **Binding conflicts**     | None — all six bindings are fresh additions                                                            |\n| **Service existence**     | ✅ All six target services exist on `origin/main`                                                      |\n| **File move/rename risk** | None — file paths identical between branches                                                           |\n| **Test impact**           | Only `connector.test.ts` and `oauth.test.ts` modified; no test infrastructure changes on `origin/main` |\n| **Config schema drift**   | `wrangler.toml` schema unchanged; only `[[services]]` blocks added                                     |\n\n**Overall Replay Risk**: **LOW** — Clean cherry-pick expected for all 11 files.\n\n---\n\n## 5. RECOMMENDATION\n\n### **A. Clean cherry-pick onto a new branch from `origin/main`**\n\n**Rationale**:\n\n1. All 11 files are unchanged on `origin/main` since the merge-base\n2. No binding name conflicts exist\n3. All target services exist and are deployed\n4. The work commit (`afbdb538`) is a single, coherent logical unit\n5. Cherry-pick will preserve authorship, commit message, and history\n6. No manual conflict resolution required\n\n### Execution Plan (when approved):\n\n```bash\n# 1. Create fresh branch from canonical origin/main\ngit fetch origin\ngit checkout -b option-b/wave0-gateway-decoupling origin/main\n\n# 2. Cherry-pick the work commit (single commit, clean)\ngit cherry-pick afbdb538\n\n# 3. Verify all 11 files applied correctly\ngit diff origin/main --stat\n\n# 4. Run typecheck/lint (if tooling available)\n# npm run typecheck && npm run lint\n\n# 5. Push for PR\ngit push -u origin option-b/wave0-gateway-decoupling\n```\n\n---\n\n## 6. BRANCH STRATEGY GOING FORWARD\n\n| Phase             | Branch                                 | Base                 | Purpose                                                       |\n| ----------------- | -------------------------------------- | -------------------- | ------------------------------------------------------------- |\n| **Wave 0 (done)** | `option-b/wave0-gateway-decoupling`    | `origin/main`        | Gateway + Connector service bindings                          |\n| **Wave 1**        | `option-b/wave1-intelligence-pipeline` | `option-b/wave0-...` | Intelligence (think/act/govern) + Pipeline (normalizer/spine) |\n| **Wave 2**        | `option-b/wave2-...`                   | `option-b/wave1-...` | Remaining services                                            |\n\n**Never** rebase `gateway-decoupling-complete` (remote is stale).  \n**Never** merge `main` → feature branch (linear history required).  \n**Always** cherry-pick forward from `origin/main` for each new wave.\n\n---\n\n## 7. ARTIFACTS PRESERVED\n\nThe following work artifacts exist in commit `afbdb538` (local only, recoverable via reflog `HEAD@{9}`):\n\n- `services/gateway/src/index.ts` — ADMIN/BILLING/TENANTS routing via service bindings\n- `services/gateway/wrangler.toml` — `[[services]]` for ADMIN, BILLING, TENANTS (default/test/prod)\n- `services/connector/src/index.ts` — LOADER/MCP/STORE routing via service bindings\n- `services/connector/wrangler.toml` — `[[services]]` for LOADER, MCP, STORE (default/test/prod)\n- `services/mcp-connector/src/lib/oauth-jwt.ts` — Shared JWT signing utility (decoupled from gateway)\n- `services/mcp-connector/src/oauth.test.ts` — Updated import path\n- `services/loader/src/lib/nango.ts` + `token-refresh.ts` — Loader library modules\n- `services/connector/src/connector.test.ts` — Integration test suite\n- `OPTION_B_WAVE0_LOG.md` — Wave 0 completion log\n\n---\n\n## 8. DECISION REQUIRED\n\n**Approve Option A** to proceed with clean cherry-pick onto new branch from `origin/main`.\n\nOnce approved, Wave 1 (Intelligence + Pipeline decoupling) can begin on the validated Wave 0 base.\n"}