Skip to content

Commit 227a563

Browse files
committed
On branch edburns/dd-2984436-make-copilot-cli-versions-consistent
modified: CONTRIBUTING.md - Simplify this after realizing the POM can handle the `npm ci`. modified: pom.xml - Ensure the COPILOT_CLI_PATH is set to the built-in Copilot CLI instance. This ensures a user's local Copilot instance, which is not guaranteed to be the correct version, and thus the correct RPC protocol, will get in the way.
1 parent 477398e commit 227a563

2 files changed

Lines changed: 54 additions & 33 deletions

File tree

CONTRIBUTING.md

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,9 @@ If you have ideas for entirely new features, please post an issue or start a dis
4040

4141
### Running locally, including tests and linters
4242

43-
```bash
44-
# Obtain the pinned version of Copilot CLI to the local workarea.
45-
# This clones the reference implementation at the commit pinned in
46-
# .lastmerge, but does NOT run `npm ci` inside its nodejs/ subdir.
47-
mvn generate-test-resources
48-
49-
# Install the pinned Copilot CLI into target/copilot-sdk/nodejs/node_modules
50-
# so the SDK tests use the version declared in
51-
# target/copilot-sdk/nodejs/package.json (the SDK-test pin), NOT the version
52-
# in target/copilot-sdk/test/harness/package.json (the replay-harness pin,
53-
# which is incidental and may be older).
54-
55-
## POSIX
56-
57-
(cd target/copilot-sdk/nodejs && npm ci --ignore-scripts)
58-
59-
## PowerShell
60-
61-
Push-Location target\copilot-sdk\nodejs; if ($?) { npm ci --ignore-scripts }; Pop-Location
62-
63-
# Make it so the pinned Copilot CLI is used for the tests. The patterns
64-
# below are scoped to the `nodejs/node_modules/` subtree so they cannot
65-
# accidentally pick up the older harness copy under
66-
# target/copilot-sdk/test/harness/node_modules/.
67-
68-
## POSIX
69-
70-
export COPILOT_CLI_PATH="$(find "$PWD/target" -type f -path '*/nodejs/node_modules/@github/copilot/index.js' | head -n 1)"
71-
72-
## PowerShell
73-
74-
$env:COPILOT_CLI_PATH = (Get-ChildItem -Path "$PWD\target" -Recurse -Filter 'index.js' -File | Where-Object { $_.FullName -match '[\\/]nodejs[\\/]node_modules[\\/]@github[\\/]copilot[\\/]index\.js$' } | Select-Object -First 1 -ExpandProperty FullName)
43+
The POM has logic to ensure a known correct installation of Copilot CLI is used when executing the tests. If you want to test against a different installation of Copilot CLI, set the value of the `copilot.cli.path` maven property to the fully qualified path to the Copilot CLI.
7544

45+
```bash
7646
# Build and run all tests
7747
mvn clean verify
7848

@@ -86,17 +56,19 @@ mvn spotless:apply
8656
mvn spotless:check
8757
```
8858

89-
Assuming you are in the same shell you used to run the above commands, to run this exact Copilot CLI locally you can do the following.
59+
## Running the known correct Copilot CLI installation
9060

9161
### POSIX
9262

9363
```bash
64+
export COPILOT_CLI_PATH="$(find "$PWD/target" -type f -path '*/nodejs/node_modules/@github/copilot/index.js' | head -n 1)"
9465
node ${COPILOT_CLI_PATH}
9566
```
9667

9768
### PowerShell
9869

9970
```PowerShell
71+
$env:COPILOT_CLI_PATH = (Get-ChildItem -Path "$PWD\target" -Recurse -Filter 'index.js' -File | Where-Object { $_.FullName -match '[\\/]nodejs[\\/]node_modules[\\/]@github[\\/]copilot[\\/]index\.js$' } | Select-Object -First 1 -ExpandProperty FullName)
10072
node $env:COPILOT_CLI_PATH
10173
```
10274

pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
<!-- Directory where the copilot-sdk repo will be cloned for tests -->
5050
<copilot.sdk.clone.dir>${project.build.directory}/copilot-sdk</copilot.sdk.clone.dir>
5151
<copilot.tests.dir>${copilot.sdk.clone.dir}/test</copilot.tests.dir>
52+
<!--
53+
Path to the Copilot CLI entry point used by the SDK tests. Defaults
54+
to the CLI installed under target/copilot-sdk/nodejs by the
55+
install-nodejs-cli-dependencies execution. Surefire injects this
56+
into the test JVM as the COPILOT_CLI_PATH environment variable, so
57+
`mvn verify` is self-contained and the developer never has to set
58+
it manually. Override on the command line to point at a different
59+
CLI build, e.g.:
60+
mvn verify -Dcopilot.cli.path=/some/other/copilot/index.js
61+
-->
62+
<copilot.cli.path>${copilot.sdk.clone.dir}/nodejs/node_modules/@github/copilot/index.js</copilot.cli.path>
5263
<!-- Set to true (via -Pskip-test-harness) to skip git-clone + npm install of test harness -->
5364
<skip.test.harness>false</skip.test.harness>
5465
<!-- Extra JVM args for Surefire; overridden by the jdk21+ profile -->
@@ -261,6 +272,35 @@
261272
</arguments>
262273
</configuration>
263274
</execution>
275+
<!--
276+
Install the @github/copilot CLI declared by
277+
target/copilot-sdk/nodejs/package.json. This is the CLI
278+
version the SDK tests must run against (independent of
279+
the older pin in test/harness/package.json which is
280+
incidental to harness internals). Mirrors what
281+
.github/workflows/build-test.yml does manually so that
282+
`mvn clean verify` is self-contained: the prior
283+
target/copilot-sdk/nodejs/node_modules is wiped by
284+
clean, but this re-creates it before tests run.
285+
Uses npm ci with the ignore-scripts flag, matching
286+
build-test.yml.
287+
-->
288+
<execution>
289+
<id>install-nodejs-cli-dependencies</id>
290+
<phase>generate-test-resources</phase>
291+
<goals>
292+
<goal>exec</goal>
293+
</goals>
294+
<configuration>
295+
<skip>${skip.test.harness}</skip>
296+
<executable>npm</executable>
297+
<workingDirectory>${copilot.sdk.clone.dir}/nodejs</workingDirectory>
298+
<arguments>
299+
<argument>ci</argument>
300+
<argument>--ignore-scripts</argument>
301+
</arguments>
302+
</configuration>
303+
</execution>
264304
</executions>
265305
</plugin>
266306
<plugin>
@@ -274,6 +314,15 @@
274314
<copilot.tests.dir>${copilot.tests.dir}</copilot.tests.dir>
275315
<copilot.sdk.dir>${copilot.sdk.clone.dir}</copilot.sdk.dir>
276316
</systemPropertyVariables>
317+
<!--
318+
Set COPILOT_CLI_PATH for the forked test JVM so the SDK
319+
tests transparently use the pinned CLI under
320+
target/copilot-sdk/nodejs/. See the copilot.cli.path
321+
property above for the override mechanism.
322+
-->
323+
<environmentVariables>
324+
<COPILOT_CLI_PATH>${copilot.cli.path}</COPILOT_CLI_PATH>
325+
</environmentVariables>
277326
</configuration>
278327
</plugin>
279328
<!-- Add src/generated/java as an additional source root -->

0 commit comments

Comments
 (0)