MCPcopy Create free account
hub / github.com/github/copilot-sdk / E2ETestContext

Class E2ETestContext

java/src/test/java/com/github/copilot/E2ETestContext.java:55–532  ·  view source on GitHub ↗

E2E test context that manages the test environment including the CapiProxy, working directories, and CLI path. This provides a complete test environment similar to the Node.js, .NET, Go, and Python SDK test harnesses. It manages: A replaying CapiProxy for deterministic API respons

Source from the content-addressed store, hash-verified

53 * </pre>
54 */
55public class E2ETestContext implements AutoCloseable {
56
57 private static final Logger LOG = Logger.getLogger(E2ETestContext.class.getName());
58
59 /**
60 * The default GitHub token used by the CLI in e2e tests. The proxy resolves
61 * this token to the default Copilot user registered at context creation.
62 */
63 private static final String DEFAULT_GITHUB_TOKEN = "fake-token-for-e2e-tests";
64 private static final Pattern SNAKE_CASE = Pattern.compile("[^a-zA-Z0-9]");
65 private static final Pattern USER_CONTENT_PATTERN = Pattern
66 .compile("^\\s+-\\s+role:\\s+user\\s*$\\s+content:\\s*(.+?)$", Pattern.MULTILINE);
67
68 private final String cliPath;
69 private final Path homeDir;
70 private final Path workDir;
71 private String proxyUrl;
72 private final CapiProxy proxy;
73 private final Path repoRoot;
74 private Path currentSnapshotFile;
75
76 private E2ETestContext(String cliPath, Path homeDir, Path workDir, String proxyUrl, CapiProxy proxy,
77 Path repoRoot) {
78 this.cliPath = cliPath;
79 this.homeDir = homeDir;
80 this.workDir = workDir;
81 this.proxyUrl = proxyUrl;
82 this.proxy = proxy;
83 this.repoRoot = repoRoot;
84 }
85
86 /**
87 * Creates a new E2E test context.
88 *
89 * @return the test context
90 * @throws IOException
91 * if setup fails
92 * @throws InterruptedException
93 * if setup is interrupted
94 */
95 public static E2ETestContext create() throws IOException, InterruptedException {
96 Path repoRoot = findRepoRoot();
97 String cliPath = getCliPath(repoRoot);
98
99 Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
100 Path homeDir = Files.createTempDirectory(tempDir, "copilot-test-config-");
101 Path workDir = Files.createTempDirectory(tempDir, "copilot-test-work-");
102
103 CapiProxy proxy = new CapiProxy();
104 String proxyUrl = proxy.start();
105
106 // Register a default Copilot user for the CLI's default token so the proxy's
107 // /copilot_internal/user endpoint returns a valid user (HTTP 200) instead of
108 // 401 "Bad credentials". CLI 1.0.64-1 gates MCP enablement on this user:
109 // `is_mcp_enabled` (added by the proxy) is the global gate, and snake_case
110 // `copilot_plan` makes the third-party MCP policy resolver early-return
111 // allow-all for non-org plans (anything other than business/enterprise),
112 // avoiding a /copilot/mcp_registry network call the proxy does not serve.

Callers 3

ctxFunction · 0.90
ctxFunction · 0.90

Calls 2

compileMethod · 0.80
getNameMethod · 0.45

Tested by 3

ctxFunction · 0.72
ctxFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…