Skip to content

Commit 391f9ef

Browse files
committed
Verify OpenCLI help metadata does not establish provenance
1 parent 9f94dba commit 391f9ef

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/test/java/io/github/easy4j/opencli/capability/OpenCliCapabilityDiscoveryTest.java‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ void rootProbePreservesUnknownSourceAndUsesOnlyDescriptiveCommands() {
4646
}
4747
}
4848

49+
@Test
50+
void siteHelpDoesNotAttributeAnOverrideToTheBundledAdapter() {
51+
OpenCliProperties properties = properties("structured");
52+
try (OpenCliClient client = new OpenCliClient(properties)) {
53+
OpenCliCapabilitySnapshot original = client.discoverCapabilities(OpenCliHelpScope.SITE_NPM_SEARCH);
54+
properties.getEnvironment().put("OPENCLI_TEST_HELP_MODE", "unverified-override");
55+
OpenCliCapabilitySnapshot overridden = client.discoverCapabilities(OpenCliHelpScope.SITE_NPM_SEARCH);
56+
57+
assertEquals(OpenCliCapabilitySnapshot.Status.AVAILABLE, original.getStatus());
58+
assertEquals(OpenCliCapabilitySnapshot.Status.AVAILABLE, overridden.getStatus());
59+
assertEquals(original.getObservedVersion(), overridden.getObservedVersion());
60+
assertEquals(original.getHelp().getSchema().getCommand(), overridden.getHelp().getSchema().getCommand());
61+
assertEquals("UNKNOWN", original.getCommandOrigin());
62+
assertEquals("UNKNOWN", overridden.getCommandOrigin());
63+
assertEquals("SITE_NPM_SEARCH", overridden.getScope());
64+
assertNotEquals(original.getHelpSha256(), overridden.getHelpSha256());
65+
assertTrue(overridden.getHelp().getSchema().getSourceJson().contains("override-test-description"));
66+
}
67+
}
68+
4969
@Test
5070
void plainHelpLeavesLocalInvocationAvailable() {
5171
try (OpenCliClient client = new OpenCliClient(properties("plain"))) {
@@ -327,7 +347,13 @@ public static void main(String[] args) throws Exception {
327347
case "npm search": fixture = "site-npm-search.json"; break;
328348
default: throw new IllegalArgumentException("Unapproved fixture command");
329349
}
330-
System.out.print(readFixture("wrong-help".equals(mode) ? "root.json" : fixture));
350+
String help = readFixture("wrong-help".equals(mode) ? "root.json" : fixture);
351+
if ("unverified-override".equals(mode) && "npm search".equals(path)) {
352+
String json = help.trim();
353+
help = json.substring(0, json.length() - 1)
354+
+ ",\"origin\":\"bundled\",\"complete\":true,\"detail_fixture\":\"override-test-description\"}";
355+
}
356+
System.out.print(help);
331357
return;
332358
}
333359
if (!Arrays.equals(args, new String[]{"--help", "-f", "json"})) {

0 commit comments

Comments
 (0)