Skip to content

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

refactor(tests): import production helpers instead of inlining copies in tests

Adam Eivyd72835f52c60
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 61259b2429..9ccf72f2a0 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -17,6 +17,7 @@
- Personal Goals dashboard widget: shows top-level goals with progress bars, category icons, horizon labels, and stall detection (14+ days idle) — replaces broken CoS task-based goal widget that never rendered
## Changed
+- Exported `isTruthyMeta` from `subAgentSpawner.js` and `applyAppWorktreeDefault` from `cos.js`; tests now import production helpers instead of duplicating their logic inline
- Consolidated 5 duplicate `timeAgo`/`formatTimeAgo` implementations into a single `timeAgo()` in `utils/formatters.js`
- Deduplicated `stripCodeFences` from insightsService — now imports from shared `lib/aiProvider.js`
- Added `MINUTE` time constant to `lib/fileUtils.js` alongside existing `HOUR`/`DAY`
diff --git a/server/services/cos.js b/server/services/cos.js
index c85823d431..f6fce23a19 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -1867,7 +1867,7 @@ Use model: claude-opus-4-5-20251101 for thorough security analysis`
* @returns {Object} Generated task
*/
// Apply app-level worktree/PR defaults only when not already set by task-type metadata
-function applyAppWorktreeDefault(metadata, app) {
+export function applyAppWorktreeDefault(metadata, app) {
if (metadata.useWorktree === undefined) {
if (app.defaultUseWorktree === true) {
metadata.useWorktree = true;
diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.js
index f723ed1f9b..e1cdb00f08 100644
--- a/server/services/subAgentSpawner.js
+++ b/server/services/subAgentSpawner.js
@@ -40,7 +40,7 @@ const AGENTS_DIR = PATHS.cosAgents;
const RUNS_DIR = PATHS.runs;
// Metadata booleans may arrive as true or 'true' (from JSON vs form/URL params)
-const isTruthyMeta = (value) => value === true || value === 'true';
+export const isTruthyMeta = (value) => value === true || value === 'true';
/**
* Extract task type key for learning lookup
@@ -2693,8 +2693,8 @@ ${worktreeInfo.baseBranch ? `- **Based on**: \`${worktreeInfo.baseBranch}\` (lat
After completing your work and before committing, run \`/simplify\` to review the changed code for reuse, quality, and efficiency. Fix any issues found before committing.
` : '';
- // Build review loop section if enabled
- const reviewLoopSection = task.metadata?.reviewLoop ? `
+ // Build review loop section if enabled (only when the agent creates the PR itself, not when openPR auto-creates it post-exit)
+ const reviewLoopSection = (task.metadata?.reviewLoop && !willOpenPR) ? `
## Review Loop
After opening the PR, run \`/do:rpr\` to resolve PR review feedback and complete the merge validation. Continue running the review loop until all checks pass and the PR is approved.
` : '';
diff --git a/server/services/subAgentSpawner.test.js b/server/services/subAgentSpawner.test.js
index 63d3b50005..73b1bbe723 100644
--- a/server/services/subAgentSpawner.test.js
+++ b/server/services/subAgentSpawner.test.js
@@ -1,11 +1,13 @@
import { describe, it, expect } from 'vitest';
+import { isTruthyMeta } from './subAgentSpawner.js';
+import { applyAppWorktreeDefault } from './cos.js';
/**
* Tests for the subAgentSpawner service
*
- * Note: We test the pure functions directly by extracting their logic.
- * The spawner has complex dependencies (process spawning, file system, etc.)
- * so we focus on the decision-making logic that can be unit tested.
+ * Note: We test the pure functions directly by importing them from production.
+ * For functions with complex dependencies (process spawning, file system, etc.)
+ * we focus on the decision-making logic that can be unit tested.
*/
// Test model selection logic
@@ -671,10 +673,8 @@ describe('Task Failure Retry Logic', () => {
});
});
- // --- isTruthyMeta helper (inline copy for testing) ---
+ // --- isTruthyMeta helper (imported from production) ---
describe('isTruthyMeta', () => {
- const isTruthyMeta = (value) => value === true || value === 'true';
-
it('should return true for boolean true', () => {
expect(isTruthyMeta(true)).toBe(true);
});
@@ -696,10 +696,9 @@ describe('Task Failure Retry Logic', () => {
});
});
- // --- openPR worktree decision logic ---
+ // --- openPR worktree decision logic (uses imported isTruthyMeta) ---
describe('openPR/useWorktree decision logic', () => {
function resolveWorktreeFlags(metadata) {
- const isTruthyMeta = (v) => v === true || v === 'true';
const explicitOpenPR = isTruthyMeta(metadata?.openPR);
const explicitWorktree = isTruthyMeta(metadata?.useWorktree) || explicitOpenPR;
return { explicitOpenPR, explicitWorktree };
@@ -742,29 +741,8 @@ describe('Task Failure Retry Logic', () => {
});
});
- // --- applyAppWorktreeDefault logic ---
+ // --- applyAppWorktreeDefault logic (imported from production cos.js) ---
describe('applyAppWorktreeDefault', () => {
- function applyAppWorktreeDefault(metadata, app) {
- if (metadata.useWorktree === undefined) {
- if (app.defaultUseWorktree === true) {
- metadata.useWorktree = true;
- } else if (app.defaultUseWorktree === false) {
- metadata.useWorktree = false;
- }
- }
- if (metadata.openPR === undefined && metadata.useWorktree !== false) {
- if (app.defaultOpenPR === true) {
- metadata.openPR = true;
- metadata.useWorktree = true;
- } else if (app.defaultOpenPR === false) {
- metadata.openPR = false;
- }
- }
- if (metadata.useWorktree === false) {
- metadata.openPR = false;
- }
- }
-
it('should fill defaults when metadata has no worktree/openPR fields', () => {
const metadata = {};
applyAppWorktreeDefault(metadata, { defaultUseWorktree: true, defaultOpenPR: true });