Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("CheckpointDiffQueryLive", () => {
);

const expectedFromRef = checkpointRefForThreadTurnStart(threadId, TurnId.makeUnsafe("turn-1"));
expect(hasCheckpointRefCalls).toEqual([expectedFromRef, expectedFromRef, toCheckpointRef]);
expect(hasCheckpointRefCalls).toEqual([expectedFromRef, toCheckpointRef]);
expect(diffCheckpointsCalls).toEqual([
{
cwd: "/tmp/workspace",
Expand Down
12 changes: 8 additions & 4 deletions apps/server/src/checkpointing/Layers/CheckpointDiffQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const make = Effect.gen(function* () {
detail: `Checkpoint diff is not available yet for turn ${input.toTurnCount}.`,
});
}
let fromCheckpointExists = false;
if (input.toTurnCount === input.fromTurnCount + 1) {
const turnStartCheckpointRef = checkpointRefForThreadTurnStart(
input.threadId,
Expand All @@ -143,15 +144,18 @@ const make = Effect.gen(function* () {
});
if (turnStartExists) {
fromCheckpointRef = turnStartCheckpointRef;
fromCheckpointExists = true;
}
}

const [fromExists, toExists] = yield* Effect.all(
[
checkpointStore.hasCheckpointRef({
cwd: workspaceCwd,
checkpointRef: fromCheckpointRef,
}),
fromCheckpointExists
? Effect.succeed(true)
: checkpointStore.hasCheckpointRef({
cwd: workspaceCwd,
checkpointRef: fromCheckpointRef,
}),
checkpointStore.hasCheckpointRef({
cwd: workspaceCwd,
checkpointRef: toCheckpointRef,
Expand Down
110 changes: 107 additions & 3 deletions apps/server/src/provider/Layers/ProviderHealth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, assert } from "@effect/vitest";
import { DEFAULT_SERVER_SETTINGS } from "@jcode/contracts";
import { Effect, FileSystem, Layer, Path, Sink, Stream } from "effect";
import * as PlatformError from "effect/PlatformError";
import { ChildProcessSpawner } from "effect/unstable/process";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";

import {
checkClaudeProviderStatus,
Expand All @@ -19,8 +19,12 @@ import {
makeCheckOpenCodeProviderStatus,
parseAuthStatusFromOutput,
parseClaudeAuthStatusFromOutput,
ProviderHealthLive,
readCodexConfigModelProvider,
} from "./ProviderHealth";
import { ServerConfig } from "../../config";
import { ServerSettingsService } from "../../serverSettings";
import { ProviderHealth } from "../Services/ProviderHealth";

// ── Test helpers ────────────────────────────────────────────────────

Expand All @@ -45,6 +49,7 @@ function mockSpawnerLayer(
handler: (
args: ReadonlyArray<string>,
command: string,
options: ChildProcess.CommandOptions,
) => {
stdout: string;
stderr: string;
Expand All @@ -54,12 +59,36 @@ function mockSpawnerLayer(
return Layer.succeed(
ChildProcessSpawner.ChildProcessSpawner,
ChildProcessSpawner.make((command) => {
const cmd = command as unknown as { command: string; args: ReadonlyArray<string> };
return Effect.succeed(mockHandle(handler(cmd.args, cmd.command)));
const cmd = command as unknown as {
command: string;
args: ReadonlyArray<string>;
options: ChildProcess.CommandOptions;
};
return Effect.succeed(mockHandle(handler(cmd.args, cmd.command, cmd.options)));
}),
);
}

function withProcessPlatform<A, E, R>(
platform: NodeJS.Platform,
effect: Effect.Effect<A, E, R>,
): Effect.Effect<A, E, R> {
return Effect.acquireUseRelease(
Effect.sync(() => {
const descriptor = Object.getOwnPropertyDescriptor(process, "platform");
Object.defineProperty(process, "platform", { value: platform });
return descriptor;
}),
() => effect,
(descriptor) =>
Effect.sync(() => {
if (descriptor) {
Object.defineProperty(process, "platform", descriptor);
}
}),
);
}

function failingSpawnerLayer(description: string) {
return Layer.succeed(
ChildProcessSpawner.ChildProcessSpawner,
Expand Down Expand Up @@ -858,6 +887,81 @@ it.layer(NodeServices.layer)("ProviderHealth", (it) => {
);
});

// ── provider update command tests ──────────────────────────────────

describe("updateProvider", () => {
it.effect("runs provider update commands through a shell on Windows", () => {
const calls: Array<{
args: ReadonlyArray<string>;
command: string;
shell: ChildProcess.CommandOptions["shell"];
}> = [];

return withProcessPlatform(
"win32",
Effect.gen(function* () {
const providerHealth = yield* ProviderHealth;
const result = yield* providerHealth.updateProvider({ provider: "cursor" });

assert.strictEqual(result.providers.length, 0);
assert.deepStrictEqual(calls, [
{
args: ["update"],
command: "agent",
shell: true,
},
]);
}),
).pipe(
Effect.provide(ProviderHealthLive),
Effect.provide(
mockSpawnerLayer((args, command, options) => {
calls.push({ args, command, shell: options.shell });
return { stdout: "", stderr: "update failed", code: 1 };
}),
),
Effect.provide(ServerSettingsService.layerTest()),
Effect.provide(ServerConfig.layerTest(process.cwd(), { prefix: "jcode-provider-health-" })),
);
});
});

describe("updateProvider", () => {
it.effect("runs provider update commands through a shell on Windows", () => {
const calls: Array<{
command: string;
args: ReadonlyArray<string>;
shell: ChildProcess.CommandOptions["shell"];
}> = [];

return withProcessPlatform(
"win32",
Effect.gen(function* () {
const providerHealth = yield* ProviderHealth;
yield* providerHealth.updateProvider({ provider: "cursor" });
}).pipe(
Effect.provide(ProviderHealthLive),
Effect.provide(ServerSettingsService.layerTest()),
Effect.provide(
ServerConfig.layerTest(process.cwd(), { prefix: "jcode-provider-health-" }),
),
Effect.provide(
mockSpawnerLayer((args, command, options) => {
calls.push({ command, args, shell: options.shell });
return { stdout: "", stderr: "update failed\n", code: 1 };
}),
),
),
).pipe(
Effect.tap(() =>
Effect.sync(() => {
assert.deepStrictEqual(calls, [{ command: "agent", args: ["update"], shell: true }]);
}),
),
);
});
});

// ── parseClaudeAuthStatusFromOutput pure tests ────────────────────

describe("parseClaudeAuthStatusFromOutput", () => {
Expand Down
56 changes: 56 additions & 0 deletions apps/web/src/hooks/useTheme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { afterEach, describe, expect, it, vi } from "vitest";

import { DEFAULT_THEME_STATE } from "../theme/theme.logic";

function installThemeDom() {
const classList = {
add: vi.fn(),
remove: vi.fn(),
toggle: vi.fn(),
};
const style = {
removeProperty: vi.fn(),
setProperty: vi.fn(),
};
const root = {
classList,
offsetHeight: 0,
setAttribute: vi.fn(),
style,
};

vi.stubGlobal("document", { documentElement: root });
vi.stubGlobal("localStorage", {
getItem: vi.fn(() => null),
setItem: vi.fn(),
});
vi.stubGlobal("window", {
matchMedia: vi.fn(() => ({ matches: false })),
});

return { classList, root, style };
}

afterEach(() => {
vi.resetModules();
vi.unstubAllGlobals();
});

describe("applyThemeState", () => {
it("does not rewrite DOM attributes or variables for identical theme inputs", async () => {
const dom = installThemeDom();
const { applyThemeState } = await import("./useTheme");

const initialAttributeWrites = dom.root.setAttribute.mock.calls.length;
const initialClassToggles = dom.classList.toggle.mock.calls.length;
const initialVariableWrites = dom.style.setProperty.mock.calls.length;
const initialVariableRemovals = dom.style.removeProperty.mock.calls.length;

applyThemeState(DEFAULT_THEME_STATE);

expect(dom.root.setAttribute).toHaveBeenCalledTimes(initialAttributeWrites);
expect(dom.classList.toggle).toHaveBeenCalledTimes(initialClassToggles);
expect(dom.style.setProperty).toHaveBeenCalledTimes(initialVariableWrites);
expect(dom.style.removeProperty).toHaveBeenCalledTimes(initialVariableRemovals);
});
});
2 changes: 1 addition & 1 deletion apps/web/src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function subscribe(listener: () => void): () => void {

// ─── DOM projection ───────────────────────────────────────────────────────

function applyThemeState(state: ThemeState, suppressTransitions = false) {
export function applyThemeState(state: ThemeState, suppressTransitions = false) {
if (typeof document === "undefined" || typeof window === "undefined") {
return;
}
Expand Down
52 changes: 52 additions & 0 deletions docs/superpowers/plans/2026-05-24-upstream-quality-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Upstream Quality Imports Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Import three high-value upstream ideas into JCode with local tests and minimal, idiomatic adaptations.

## File Structure

- `docs/superpowers/specs/2026-05-24-upstream-quality-imports-design.md`: approved design for the import tranche.
- `docs/superpowers/plans/2026-05-24-upstream-quality-imports.md`: this implementation plan.
- `apps/web/src/hooks/useTheme.ts`: theme mode resolution and DOM synchronization seam.
- `apps/web/src/hooks/useTheme.test.ts` or existing theme hook/runtime test file: focused tests for repeated theme sync no-op behavior.
- `apps/server/src/provider/Layers/ProviderHealth.ts`: provider update command execution seam.
- `apps/server/src/provider/Layers/ProviderHealth.test.ts`: focused tests that update commands run through a shell on Windows.
- `apps/server/src/checkpointing/Layers/CheckpointDiffQuery.ts`: checkpoint diff query seam for narrow hot-path improvement.
- `apps/server/src/checkpointing/Layers/CheckpointDiffQuery.test.ts`: focused tests for scoped diff reads and stable checkpoint lookup behavior.
- `apps/web/src/components/DiffPanel.tsx`: only touch if server-side diff seam cannot fully address the hot path.

## Tasks

- [ ] Create or update a focused theme sync test that fails because repeated identical theme application rewrites DOM state.
- [ ] Run the focused theme test and confirm the failure is the expected repeated-write assertion.
- [ ] Implement the smallest theme sync no-op cache in `useTheme.ts` or a helper extracted from it.
- [ ] Run the focused theme test and confirm it passes.
- [ ] Create or update a focused provider update test for Windows shell execution.
- [ ] Run the focused provider test and confirm the expected shell assertion.
- [ ] Implement the provider update Windows-shell adaptation in `ProviderHealth.ts` if the test shows it is missing, without changing update locking or result reporting.
- [ ] Run the focused provider test and confirm it passes.
- [ ] Inspect `CheckpointDiffQuery` current tests and choose one narrow DPCode #129 hot-path behavior that is locally testable.
- [ ] Create or update a focused checkpoint diff test that fails for the chosen hot-path behavior.
- [ ] Run the focused checkpoint diff test and confirm the expected failure.
- [ ] Implement the smallest checkpoint/diff adaptation needed to pass the test.
- [ ] Run the focused checkpoint diff test and confirm it passes.
- [ ] Run focused workspace tests for all touched areas.
- [ ] Run `bun run --cwd apps/web typecheck` and `bun run --cwd apps/server typecheck`.
- [ ] Run `bun run fmt:check -- <touched files>`.
- [ ] Run LSP diagnostics for touched TypeScript files.
- [ ] Run Aikido full scan on modified first-party code.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
## Acceptance Criteria

- [ ] Reapplying the same theme inputs is a no-op while real theme changes still apply.
- [ ] Provider update commands run through a shell on Windows.
- [ ] One narrow diff/checkpoint hot-path improvement is implemented and tested.
- [ ] No upstream branch is merged wholesale or copied 1:1 without local adaptation.
- [ ] All focused verification and security checks pass or are reported with exact evidence.

## Notes

- Keep the slices independently revertible.
- Stop and defer the DPCode diff slice if it expands beyond a narrow tested seam.
- Prefer strengthening existing JCode tests when an upstream idea is already implemented.
Loading
Loading