Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: break the git service import cycle (#8035)
[._.]/ Adam Eivy188e7f638596
diff --git a/server/routes/git.js b/server/routes/git.jsindex 92a371d82b..e94eee714b 100644--- a/server/routes/git.js+++ b/server/routes/git.js@@ -2,6 +2,7 @@ import { Router } from 'express';import { existsSync, statSync, realpathSync } from 'fs';import { resolve } from 'path';import * as git from '../services/git.js';+import * as gitSubmodules from '../services/gitSubmodules.js';import * as appsService from '../services/apps.js';import { getAgents } from '../services/cosAgentLifecycle.js';import { protectedAgentIds } from '../services/agentState.js';@@ -68,7 +69,7 @@ const router = Router();router.get('/submodules/status', asyncHandler(async (req, res) => {const { repoPath } = validateRequest(submoduleStatusQuerySchema, req.query);if (repoPath) assertAllowedWorkspace(repoPath);- res.json(await git.getSubmoduleOverview(repoPath));+ res.json(await gitSubmodules.getSubmoduleOverview(repoPath));}));// POST /api/git/submodules/update - Update a specific submodule@@ -77,7 +78,7 @@ router.post('/submodules/update', asyncHandler(async (req, res) => {if (repoPath) assertAllowedWorkspace(repoPath);// The service owns the "is this a real submodule of that repo?" check and// throws a 400 ServerError — re-listing them here would just spawn git twice.- const result = await git.updateSubmodule(path, { repoPath, commit });+ const result = await gitSubmodules.updateSubmodule(path, { repoPath, commit });res.json({ success: true, ...result });}));diff --git a/server/routes/git.test.js b/server/routes/git.test.jsindex e4ad6062b1..735019cbac 100644--- a/server/routes/git.test.js+++ b/server/routes/git.test.js@@ -14,10 +14,6 @@ vi.mock('../services/git.js', () => ({push: vi.fn().mockResolvedValue({ pushed: true }),getGitInfo: vi.fn().mockResolvedValue({}),getBranches: vi.fn().mockResolvedValue([]),- getSubmodules: vi.fn().mockResolvedValue([]),- getSubmoduleOverview: vi.fn().mockResolvedValue({ submodules: [], defaultBranch: 'main' }),- getSubmodulePaths: vi.fn().mockResolvedValue([]),- updateSubmodule: vi.fn().mockResolvedValue({ newCommit: 'abc', committed: false }),getAppById: vi.fn(),updateBranches: vi.fn().mockResolvedValue({}),getBranchComparison: vi.fn().mockResolvedValue({}),@@ -33,6 +29,13 @@ vi.mock('../services/git.js', () => ({deleteBranch: vi.fn().mockResolvedValue({})}));+vi.mock('../services/gitSubmodules.js', () => ({+ getSubmodules: vi.fn().mockResolvedValue([]),+ getSubmoduleOverview: vi.fn().mockResolvedValue({ submodules: [], defaultBranch: 'main' }),+ getSubmodulePaths: vi.fn().mockResolvedValue([]),+ updateSubmodule: vi.fn().mockResolvedValue({ newCommit: 'abc', committed: false })+}));+vi.mock('../services/apps.js', () => ({getAppById: vi.fn()}));@@ -63,6 +66,7 @@ import { existsSync, statSync, realpathSync } from 'fs';import { isWithinAllowedRoots, outsideAllowedRootsMessage } from '../lib/workspaceRoots.js';import * as cosAgentLifecycleService from '../services/cosAgentLifecycle.js';import * as gitService from '../services/git.js';+import * as gitSubmoduleService from '../services/gitSubmodules.js';function makeApp() {const app = express();@@ -318,7 +322,7 @@ describe('git routes — submodules', () => {});it('GET /submodules/status without repoPath reads the PortOS checkout', async () => {- gitService.getSubmoduleOverview.mockResolvedValue({+ gitSubmoduleService.getSubmoduleOverview.mockResolvedValue({submodules: [{ path: 'lib/dep', name: 'dep' }],defaultBranch: 'main'});@@ -329,7 +333,7 @@ describe('git routes — submodules', () => {expect(res.status).toBe(200);expect(res.body).toEqual({ submodules: [{ path: 'lib/dep', name: 'dep' }], defaultBranch: 'main' });// Undefined, not a string — the service falls back to the PortOS checkout.- expect(gitService.getSubmoduleOverview).toHaveBeenCalledWith(undefined);+ expect(gitSubmoduleService.getSubmoduleOverview).toHaveBeenCalledWith(undefined);});it('GET /submodules/status?repoPath scopes the read to that repo', async () => {@@ -338,7 +342,7 @@ describe('git routes — submodules', () => {.get(`/api/git/submodules/status?repoPath=${encodeURIComponent(WORKSPACE)}`);expect(res.status).toBe(200);- expect(gitService.getSubmoduleOverview).toHaveBeenCalledWith(WORKSPACE);+ expect(gitSubmoduleService.getSubmoduleOverview).toHaveBeenCalledWith(WORKSPACE);});it('GET /submodules/status rejects a repoPath outside allowed roots', async () => {@@ -350,11 +354,11 @@ describe('git routes — submodules', () => {.get('/api/git/submodules/status?repoPath=%2Fetc');expect(res.status).toBe(403);- expect(gitService.getSubmoduleOverview).not.toHaveBeenCalled();+ expect(gitSubmoduleService.getSubmoduleOverview).not.toHaveBeenCalled();});it('POST /submodules/update forwards repoPath + commit and echoes the commit result', async () => {- gitService.updateSubmodule.mockResolvedValue({+ gitSubmoduleService.updateSubmodule.mockResolvedValue({newCommit: 'def4567',committed: true,commitSha: 'aaa1111',@@ -369,7 +373,7 @@ describe('git routes — submodules', () => {.send({ path: 'lib/dep', repoPath: WORKSPACE, commit: true });expect(res.status).toBe(200);- expect(gitService.updateSubmodule).toHaveBeenCalledWith('lib/dep', { repoPath: WORKSPACE, commit: true });+ expect(gitSubmoduleService.updateSubmodule).toHaveBeenCalledWith('lib/dep', { repoPath: WORKSPACE, commit: true });expect(res.body).toEqual({success: true,newCommit: 'def4567',@@ -380,7 +384,7 @@ describe('git routes — submodules', () => {currentBranch: 'main'});// The service owns the known-submodule check; the route must not re-list.- expect(gitService.getSubmodulePaths).not.toHaveBeenCalled();+ expect(gitSubmoduleService.getSubmodulePaths).not.toHaveBeenCalled();});it('POST /submodules/update defaults commit to false when the flag is absent', async () => {@@ -390,7 +394,7 @@ describe('git routes — submodules', () => {.send({ path: 'lib/dep' });expect(res.status).toBe(200);- expect(gitService.updateSubmodule).toHaveBeenCalledWith('lib/dep', { repoPath: undefined, commit: false });+ expect(gitSubmoduleService.updateSubmodule).toHaveBeenCalledWith('lib/dep', { repoPath: undefined, commit: false });});it('POST /submodules/update rejects a missing path with a 400', async () => {@@ -398,11 +402,11 @@ describe('git routes — submodules', () => {const res = await request(app).post('/api/git/submodules/update').send({});expect(res.status).toBe(400);- expect(gitService.updateSubmodule).not.toHaveBeenCalled();+ expect(gitSubmoduleService.updateSubmodule).not.toHaveBeenCalled();});it('POST /submodules/update surfaces the service 400 for an unknown submodule path', async () => {- gitService.updateSubmodule.mockRejectedValue(+ gitSubmoduleService.updateSubmodule.mockRejectedValue(Object.assign(new Error('Unknown submodule path: lib/other'), { status: 400, code: 'VALIDATION_ERROR' }));@@ -425,6 +429,6 @@ describe('git routes — submodules', () => {.send({ path: 'lib/dep', repoPath: '/etc' });expect(res.status).toBe(403);- expect(gitService.updateSubmodule).not.toHaveBeenCalled();+ expect(gitSubmoduleService.updateSubmodule).not.toHaveBeenCalled();});});diff --git a/server/services/git.js b/server/services/git.jsindex 8edb7c3848..97a2fd42cc 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -1709,10 +1709,3 @@ export async function getGitInfo(dir) {};}-export {- getSubmodules,- getSubmoduleOverview,- getSubmodulePaths,- updateSubmodule-} from './gitSubmodules.js';-diff --git a/server/services/git.submodules.test.js b/server/services/git.submodules.test.jsindex 7ef3fe3d11..bdcb1849cc 100644--- a/server/services/git.submodules.test.js+++ b/server/services/git.submodules.test.js@@ -52,7 +52,7 @@ describe('updateSubmodule', () => {it('updates without committing when commit is not requested', async () => {scriptGit();- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');const result = await updateSubmodule(SUB, { repoPath: REPO });@@ -64,7 +64,7 @@ describe('updateSubmodule', () => {it('commits the pointer bump on the default branch when commit is requested', async () => {scriptGit();- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');const result = await updateSubmodule(SUB, { repoPath: REPO, commit: true });@@ -83,7 +83,7 @@ describe('updateSubmodule', () => {it('refuses to commit when the repo is checked out on another branch', async () => {scriptGit({ defaultBranch: 'main', currentBranch: 'feature/wip' });- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');const result = await updateSubmodule(SUB, { repoPath: REPO, commit: true });@@ -99,7 +99,7 @@ describe('updateSubmodule', () => {it('reports no-changes instead of creating an empty commit', async () => {scriptGit({ stagedPointer: false });- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');const result = await updateSubmodule(SUB, { repoPath: REPO, commit: true });@@ -120,7 +120,7 @@ describe('updateSubmodule', () => {return scripted(args, cwd, options);});clearStaleGitLock.mockReturnValue('/Users/me/project/.git/modules/lib/dep/index.lock');- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');const result = await updateSubmodule(SUB, { repoPath: REPO });@@ -139,7 +139,7 @@ describe('updateSubmodule', () => {return ok(' 1111111222222233333334444444555555566 lib/dep (heads/main)\n');});clearStaleGitLock.mockReturnValue(null);- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');await expect(updateSubmodule(SUB, { repoPath: REPO })).rejects.toThrow(/Unable to create/);expect(callsFor('submodule').filter(([args]) => args[1] === 'update')).toHaveLength(1);@@ -147,19 +147,24 @@ describe('updateSubmodule', () => {it('rejects a path that is not a submodule of the repo', async () => {scriptGit();- const { updateSubmodule } = await import('./git.js');+ const { updateSubmodule } = await import('./gitSubmodules.js');await expect(updateSubmodule('lib/other', { repoPath: REPO })).rejects.toThrow(/Unknown submodule path/);expect(callsFor('submodule').filter(([args]) => args[1] === 'update')).toHaveLength(0);});- it('exports submodule operations directly from gitSubmodules.js', async () => {+ it('keeps submodule operations on their declaring service', async () => {const direct = await import('./gitSubmodules.js');const facade = await import('./git.js');- expect(direct.getSubmodules).toBe(facade.getSubmodules);- expect(direct.getSubmoduleOverview).toBe(facade.getSubmoduleOverview);- expect(direct.getSubmodulePaths).toBe(facade.getSubmodulePaths);- expect(direct.updateSubmodule).toBe(facade.updateSubmodule);+ expect(Object.keys(direct)).toEqual(expect.arrayContaining([+ 'getSubmodules',+ 'getSubmoduleOverview',+ 'getSubmodulePaths',+ 'updateSubmodule'+ ]));+ expect(facade.getSubmodules).toBeUndefined();+ expect(facade.getSubmoduleOverview).toBeUndefined();+ expect(facade.getSubmodulePaths).toBeUndefined();+ expect(facade.updateSubmodule).toBeUndefined();});});-