MCPcopy Create free account
hub / github.com/cortexkit/magic-context / fakeContext

Function fakeContext

packages/pi-plugin/src/test-utils.test.ts:127–161  ·  view source on GitHub ↗
(
	sessionId = "ses-test",
	cwd = process.cwd(),
	entryIds: string[] = ["entry-1"],
	/**
	 * Optional message references used as `entry.message` on each fake
	 * SessionEntry. Pi's runtime keeps `entry.message === sourceAgentMessage`
	 * by reference (session-manager.js:580), and Magic Context's
	 * `collectMessageEntryIdsByRef` relies on that reference identity to
	 * map event.messages → entry ids. Tests that want boundary-id
	 * resolution to work should pass the same message objects they put
	 * into `event.messages`. Without explicit messages, we fall back to
	 * synthesized userMessage instances — which intentionally do NOT
	 * match anything the test passes via `event.messages`, exercising
	 * the unmapped-slot fallback path.
	 */
	messages?: PiMessage[],
)

Source from the content-addressed store, hash-verified

125}
126
127export function fakeContext(
128 sessionId = "ses-test",
129 cwd = process.cwd(),
130 entryIds: string[] = ["entry-1"],
131 /**
132 * Optional message references used as `entry.message` on each fake
133 * SessionEntry. Pi's runtime keeps `entry.message === sourceAgentMessage`
134 * by reference (session-manager.js:580), and Magic Context's
135 * `collectMessageEntryIdsByRef` relies on that reference identity to
136 * map event.messages → entry ids. Tests that want boundary-id
137 * resolution to work should pass the same message objects they put
138 * into `event.messages`. Without explicit messages, we fall back to
139 * synthesized userMessage instances — which intentionally do NOT
140 * match anything the test passes via `event.messages`, exercising
141 * the unmapped-slot fallback path.
142 */
143 messages?: PiMessage[],
144) {
145 return {
146 cwd,
147 hasUI: true,
148 signal: new AbortController().signal,
149 ui: { notify: () => undefined },
150 sessionManager: {
151 getSessionId: () => sessionId,
152 getBranch: () =>
153 entryIds.map((id, index) => ({
154 type: "message",
155 id,
156 message: messages?.[index] ?? userMessage("", index + 1),
157 })),
158 },
159 getContextUsage: () => ({ tokens: 0, percent: 0, contextWindow: 100_000 }),
160 };
161}

Callers 10

runPassFunction · 0.90
contextForFunction · 0.90
runDrainPassFunction · 0.90
callNoteFunction · 0.90
callDropFunction · 0.90
ctx-reduce.test.tsFile · 0.90
ctx-memory.test.tsFile · 0.90
ctx-search.test.tsFile · 0.90
ctx-aug.test.tsFile · 0.90

Calls 1

userMessageFunction · 0.70

Tested by

no test coverage detected