GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): resolve Claude policy for custom homes and bound the dow… · pingdotgg/t3code@c2d9afc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2/Adapters
    • ClaudeAdapterV2.test.ts
    • ClaudeAdapterV2.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+231Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,237 @@ describe("ClaudeAdapterV2 Claude policy bypass downgrade", () => {
15751575
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
15761576
),
15771577
);
1578+
1579+
// A configured Claude home (settings.homePath) cannot be resolved through
1580+
// resolveSettings's "user" source, which always reads the ambient
1581+
// CLAUDE_CONFIG_DIR. The adapter must still honor that home's own
1582+
// settings.json instead of unconditionally assuming bypass is available
1583+
// for every instance with a configured home.
1584+
it.effect(
1585+
"honors a configured Claude home's own settings.json instead of skipping the check",
1586+
() =>
1587+
Effect.scoped(
1588+
Effect.gen(function* () {
1589+
const fileSystem = yield* FileSystem.FileSystem;
1590+
const path = yield* Path.Path;
1591+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1592+
const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
1593+
prefix: "t3-claude-bypass-policy-custom-home-",
1594+
});
1595+
const customHome = yield* fileSystem.makeTempDirectoryScoped({
1596+
prefix: "t3-claude-bypass-policy-custom-home-dir-",
1597+
});
1598+
yield* fileSystem.writeFileString(
1599+
path.join(customHome, "settings.json"),
1600+
'{"permissions":{"disableBypassPermissionsMode":"disable"}}',
1601+
);
1602+
// No restriction at the cwd itself: only the custom home's own
1603+
// settings.json should be responsible for the downgrade below.
1604+
const cwd = yield* fileSystem.makeTempDirectoryScoped({
1605+
prefix: "t3-claude-bypass-policy-custom-home-cwd-",
1606+
});
1607+
1608+
let openedOptions: ClaudeAdapterV2.ClaudeAgentSdkQueryOptions | undefined;
1609+
const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({
1610+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1611+
settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: customHome },
1612+
environment: {},
1613+
attachmentsDir,
1614+
fileSystem,
1615+
path,
1616+
idAllocator,
1617+
queryRunner: {
1618+
allocateSessionId: Effect.succeed("native-thread-claude-bypass-custom-home"),
1619+
open: (input) =>
1620+
Effect.sync(() => {
1621+
openedOptions = input.options;
1622+
return {
1623+
messages: Stream.never,
1624+
offer: () => Effect.void,
1625+
setModel: () => Effect.void,
1626+
setPermissionMode: () => Effect.void,
1627+
interrupt: Effect.void,
1628+
close: Effect.void,
1629+
};
1630+
}),
1631+
forkSession: () => Effect.die("unused"),
1632+
subagentLaunchToolUseId: () => Effect.succeed(null),
1633+
assertComplete: Effect.void,
1634+
},
1635+
});
1636+
1637+
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
1638+
runtimeMode: "full-access",
1639+
interactionMode: "default",
1640+
cwd,
1641+
});
1642+
const threadId = ThreadId.make("thread-claude-bypass-policy-custom-home");
1643+
const runtime = yield* adapter.openSession({
1644+
threadId,
1645+
providerSessionId: ProviderSessionId.make(
1646+
"provider-session-claude-bypass-policy-custom-home",
1647+
),
1648+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1649+
runtimePolicy,
1650+
});
1651+
const providerThread = yield* runtime.ensureThread({
1652+
threadId,
1653+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1654+
runtimePolicy,
1655+
});
1656+
const now = yield* DateTime.now;
1657+
1658+
yield* runtime.startTurn(
1659+
makeClaudeTestTurnInput({
1660+
threadId,
1661+
providerThread,
1662+
now,
1663+
attemptId: RunAttemptId.make("attempt-claude-bypass-policy-custom-home"),
1664+
text: "touch file.txt",
1665+
attachments: [],
1666+
runtimePolicy,
1667+
}),
1668+
);
1669+
1670+
assert.equal(openedOptions?.permissionMode, "auto");
1671+
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
1672+
),
1673+
);
1674+
1675+
it.effect(
1676+
"keeps bypassPermissions for a configured Claude home with no restricting settings.json",
1677+
() =>
1678+
Effect.scoped(
1679+
Effect.gen(function* () {
1680+
const fileSystem = yield* FileSystem.FileSystem;
1681+
const path = yield* Path.Path;
1682+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1683+
const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
1684+
prefix: "t3-claude-bypass-policy-custom-home-open-",
1685+
});
1686+
// No settings.json written here at all.
1687+
const customHome = yield* fileSystem.makeTempDirectoryScoped({
1688+
prefix: "t3-claude-bypass-policy-custom-home-open-dir-",
1689+
});
1690+
const cwd = yield* fileSystem.makeTempDirectoryScoped({
1691+
prefix: "t3-claude-bypass-policy-custom-home-open-cwd-",
1692+
});
1693+
1694+
let openedOptions: ClaudeAdapterV2.ClaudeAgentSdkQueryOptions | undefined;
1695+
const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({
1696+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1697+
settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: customHome },
1698+
environment: {},
1699+
attachmentsDir,
1700+
fileSystem,
1701+
path,
1702+
idAllocator,
1703+
queryRunner: {
1704+
allocateSessionId: Effect.succeed("native-thread-claude-bypass-custom-home-open"),
1705+
open: (input) =>
1706+
Effect.sync(() => {
1707+
openedOptions = input.options;
1708+
return {
1709+
messages: Stream.never,
1710+
offer: () => Effect.void,
1711+
setModel: () => Effect.void,
1712+
setPermissionMode: () => Effect.void,
1713+
interrupt: Effect.void,
1714+
close: Effect.void,
1715+
};
1716+
}),
1717+
forkSession: () => Effect.die("unused"),
1718+
subagentLaunchToolUseId: () => Effect.succeed(null),
1719+
assertComplete: Effect.void,
1720+
},
1721+
});
1722+
1723+
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
1724+
runtimeMode: "full-access",
1725+
interactionMode: "default",
1726+
cwd,
1727+
});
1728+
const threadId = ThreadId.make("thread-claude-bypass-policy-custom-home-open");
1729+
const runtime = yield* adapter.openSession({
1730+
threadId,
1731+
providerSessionId: ProviderSessionId.make(
1732+
"provider-session-claude-bypass-policy-custom-home-open",
1733+
),
1734+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1735+
runtimePolicy,
1736+
});
1737+
const providerThread = yield* runtime.ensureThread({
1738+
threadId,
1739+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1740+
runtimePolicy,
1741+
});
1742+
const now = yield* DateTime.now;
1743+
1744+
yield* runtime.startTurn(
1745+
makeClaudeTestTurnInput({
1746+
threadId,
1747+
providerThread,
1748+
now,
1749+
attemptId: RunAttemptId.make("attempt-claude-bypass-policy-custom-home-open"),
1750+
text: "touch file.txt",
1751+
attachments: [],
1752+
runtimePolicy,
1753+
}),
1754+
);
1755+
1756+
assert.equal(openedOptions?.permissionMode, "bypassPermissions");
1757+
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
1758+
),
1759+
);
1760+
});
1761+
1762+
// The #4927 downgrade notice is tracked per thread on the adapter instance
1763+
// with no lifecycle hook to clear an entry when a thread is deleted, so it
1764+
// must be bounded some other way instead of growing forever.
1765+
describe("ClaudeAdapterV2 bounded recent set", () => {
1766+
it("evicts the least-recently-marked entry once capacity is exceeded", () => {
1767+
const set = ClaudeAdapterV2.makeBoundedRecentSet<string>(3);
1768+
set.mark("a");
1769+
set.mark("b");
1770+
set.mark("c");
1771+
assert.isTrue(set.has("a"));
1772+
1773+
set.mark("d");
1774+
1775+
assert.isFalse(set.has("a"), "the oldest entry should have been evicted");
1776+
assert.isTrue(set.has("b"));
1777+
assert.isTrue(set.has("c"));
1778+
assert.isTrue(set.has("d"));
1779+
});
1780+
1781+
it("never grows past capacity across many distinct keys", () => {
1782+
const set = ClaudeAdapterV2.makeBoundedRecentSet<number>(10);
1783+
for (let i = 0; i < 10000; i++) {
1784+
set.mark(i);
1785+
}
1786+
let size = 0;
1787+
for (let i = 0; i < 10000; i++) {
1788+
if (set.has(i)) {
1789+
size++;
1790+
}
1791+
}
1792+
assert.isAtMost(size, 10);
1793+
// The most recently marked keys are the ones still present.
1794+
assert.isTrue(set.has(9999));
1795+
assert.isFalse(set.has(0));
1796+
});
1797+
1798+
it("treats re-marking an existing entry as a refresh, not a duplicate that skips eviction order", () => {
1799+
const set = ClaudeAdapterV2.makeBoundedRecentSet<string>(2);
1800+
set.mark("a");
1801+
set.mark("b");
1802+
set.mark("a"); // "a" is now most-recent; "b" is least-recent.
1803+
set.mark("c"); // Must evict "b", not "a".
1804+
1805+
assert.isTrue(set.has("a"));
1806+
assert.isFalse(set.has("b"));
1807+
assert.isTrue(set.has("c"));
1808+
});
15781809
});
15791810

15801811
// Opens a session with the given configured binary path and environment, runs

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.