Skip to content

Commit acd5c4a

Browse files
Copilotedburns
andauthored
test: add Optional value retrieval and JSON deserialization tests
Adds tests for getAsInt/get/orElse value retrieval on all Optional-returning getters, and JSON deserialization round-trip tests for ModelCapabilitiesOverride inner classes and InfiniteSessionConfig to keep coverage above 83%. Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent feae21b commit acd5c4a

1 file changed

Lines changed: 265 additions & 0 deletions

File tree

src/test/java/com/github/copilot/sdk/OptionalApiAndJacksonTest.java

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,271 @@ void userInputRequest_clearAllowFreeform() {
293293
assertTrue(req.getAllowFreeform().isEmpty());
294294
}
295295

296+
// ── Value retrieval through Optional getters ────────────────────────
297+
298+
@Test
299+
void copilotClientOptions_sessionIdleTimeoutSecondsValue() {
300+
var opts = new CopilotClientOptions();
301+
assertTrue(opts.getSessionIdleTimeoutSeconds().isEmpty());
302+
303+
opts.setSessionIdleTimeoutSeconds(300);
304+
assertEquals(300, opts.getSessionIdleTimeoutSeconds().getAsInt());
305+
306+
opts.setSessionIdleTimeoutSeconds(0);
307+
assertTrue(opts.getSessionIdleTimeoutSeconds().isPresent());
308+
assertEquals(0, opts.getSessionIdleTimeoutSeconds().getAsInt());
309+
}
310+
311+
@Test
312+
void copilotClientOptions_useLoggedInUserValue() {
313+
var opts = new CopilotClientOptions();
314+
assertTrue(opts.getUseLoggedInUser().isEmpty());
315+
316+
opts.setUseLoggedInUser(true);
317+
assertEquals(Boolean.TRUE, opts.getUseLoggedInUser().get());
318+
319+
opts.setUseLoggedInUser(false);
320+
assertEquals(Boolean.FALSE, opts.getUseLoggedInUser().get());
321+
}
322+
323+
@Test
324+
void sessionConfig_enableSessionTelemetryValue() {
325+
var cfg = new SessionConfig();
326+
assertFalse(cfg.getEnableSessionTelemetry().orElse(false));
327+
328+
cfg.setEnableSessionTelemetry(true);
329+
assertTrue(cfg.getEnableSessionTelemetry().orElse(false));
330+
331+
cfg.setEnableSessionTelemetry(false);
332+
assertFalse(cfg.getEnableSessionTelemetry().orElse(true));
333+
}
334+
335+
@Test
336+
void sessionConfig_enableConfigDiscoveryValue() {
337+
var cfg = new SessionConfig();
338+
assertTrue(cfg.getEnableConfigDiscovery().isEmpty());
339+
340+
cfg.setEnableConfigDiscovery(true);
341+
assertTrue(cfg.getEnableConfigDiscovery().get());
342+
343+
cfg.setEnableConfigDiscovery(false);
344+
assertFalse(cfg.getEnableConfigDiscovery().get());
345+
}
346+
347+
@Test
348+
void sessionConfig_includeSubAgentStreamingEventsValue() {
349+
var cfg = new SessionConfig();
350+
assertTrue(cfg.getIncludeSubAgentStreamingEvents().isEmpty());
351+
352+
cfg.setIncludeSubAgentStreamingEvents(true);
353+
assertTrue(cfg.getIncludeSubAgentStreamingEvents().get());
354+
}
355+
356+
@Test
357+
void resumeSessionConfig_enableSessionTelemetryValue() {
358+
var cfg = new ResumeSessionConfig();
359+
assertTrue(cfg.getEnableSessionTelemetry().isEmpty());
360+
361+
cfg.setEnableSessionTelemetry(true);
362+
assertTrue(cfg.getEnableSessionTelemetry().get());
363+
364+
cfg.setEnableSessionTelemetry(false);
365+
assertFalse(cfg.getEnableSessionTelemetry().get());
366+
}
367+
368+
@Test
369+
void resumeSessionConfig_enableConfigDiscoveryValue() {
370+
var cfg = new ResumeSessionConfig();
371+
assertTrue(cfg.getEnableConfigDiscovery().isEmpty());
372+
373+
cfg.setEnableConfigDiscovery(true);
374+
assertTrue(cfg.getEnableConfigDiscovery().get());
375+
}
376+
377+
@Test
378+
void resumeSessionConfig_includeSubAgentStreamingEventsValue() {
379+
var cfg = new ResumeSessionConfig();
380+
assertTrue(cfg.getIncludeSubAgentStreamingEvents().isEmpty());
381+
382+
cfg.setIncludeSubAgentStreamingEvents(false);
383+
assertFalse(cfg.getIncludeSubAgentStreamingEvents().get());
384+
}
385+
386+
@Test
387+
void infiniteSessionConfig_thresholdValues() {
388+
var cfg = new InfiniteSessionConfig();
389+
assertTrue(cfg.getBackgroundCompactionThreshold().isEmpty());
390+
assertTrue(cfg.getBufferExhaustionThreshold().isEmpty());
391+
392+
cfg.setBackgroundCompactionThreshold(0.6);
393+
cfg.setBufferExhaustionThreshold(0.85);
394+
assertEquals(0.6, cfg.getBackgroundCompactionThreshold().getAsDouble(), 0.001);
395+
assertEquals(0.85, cfg.getBufferExhaustionThreshold().getAsDouble(), 0.001);
396+
}
397+
398+
@Test
399+
void infiniteSessionConfig_enabledValue() {
400+
var cfg = new InfiniteSessionConfig();
401+
assertTrue(cfg.getEnabled().isEmpty());
402+
403+
cfg.setEnabled(true);
404+
assertTrue(cfg.getEnabled().get());
405+
406+
cfg.setEnabled(false);
407+
assertFalse(cfg.getEnabled().get());
408+
}
409+
410+
@Test
411+
void inputOptions_minAndMaxLengthValues() {
412+
var opts = new InputOptions();
413+
assertTrue(opts.getMinLength().isEmpty());
414+
assertTrue(opts.getMaxLength().isEmpty());
415+
416+
opts.setMinLength(1);
417+
opts.setMaxLength(255);
418+
assertEquals(1, opts.getMinLength().getAsInt());
419+
assertEquals(255, opts.getMaxLength().getAsInt());
420+
}
421+
422+
@Test
423+
void supports_visionAndReasoningEffortValues() {
424+
var s = new ModelCapabilitiesOverride.Supports();
425+
assertTrue(s.getVision().isEmpty());
426+
assertTrue(s.getReasoningEffort().isEmpty());
427+
428+
s.setVision(true);
429+
s.setReasoningEffort(false);
430+
assertTrue(s.getVision().get());
431+
assertFalse(s.getReasoningEffort().get());
432+
}
433+
434+
@Test
435+
void limits_tokenValues() {
436+
var l = new ModelCapabilitiesOverride.Limits();
437+
assertTrue(l.getMaxPromptTokens().isEmpty());
438+
assertTrue(l.getMaxOutputTokens().isEmpty());
439+
assertTrue(l.getMaxContextWindowTokens().isEmpty());
440+
441+
l.setMaxPromptTokens(4096);
442+
l.setMaxOutputTokens(1024);
443+
l.setMaxContextWindowTokens(16384);
444+
assertEquals(4096, l.getMaxPromptTokens().getAsInt());
445+
assertEquals(1024, l.getMaxOutputTokens().getAsInt());
446+
assertEquals(16384, l.getMaxContextWindowTokens().getAsInt());
447+
}
448+
449+
@Test
450+
void providerConfig_tokenValues() {
451+
var cfg = new ProviderConfig();
452+
assertTrue(cfg.getMaxPromptTokens().isEmpty());
453+
assertTrue(cfg.getMaxOutputTokens().isEmpty());
454+
455+
cfg.setMaxPromptTokens(8192);
456+
cfg.setMaxOutputTokens(2048);
457+
assertEquals(8192, cfg.getMaxPromptTokens().getAsInt());
458+
assertEquals(2048, cfg.getMaxOutputTokens().getAsInt());
459+
}
460+
461+
@Test
462+
void telemetryConfig_captureContentValue() {
463+
var cfg = new TelemetryConfig();
464+
assertTrue(cfg.getCaptureContent().isEmpty());
465+
466+
cfg.setCaptureContent(true);
467+
assertTrue(cfg.getCaptureContent().get());
468+
469+
cfg.setCaptureContent(false);
470+
assertFalse(cfg.getCaptureContent().get());
471+
}
472+
473+
@Test
474+
void sessionUiCapabilities_elicitationValue() {
475+
var caps = new SessionUiCapabilities();
476+
assertTrue(caps.getElicitation().isEmpty());
477+
assertFalse(caps.getElicitation().orElse(false));
478+
479+
caps.setElicitation(true);
480+
assertTrue(caps.getElicitation().orElse(false));
481+
}
482+
483+
@Test
484+
void customAgentConfig_inferValue() {
485+
var cfg = new CustomAgentConfig();
486+
assertTrue(cfg.getInfer().isEmpty());
487+
488+
cfg.setInfer(true);
489+
assertTrue(cfg.getInfer().get());
490+
491+
cfg.setInfer(false);
492+
assertFalse(cfg.getInfer().get());
493+
}
494+
495+
@Test
496+
void userInputRequest_allowFreeformValue() {
497+
var req = new UserInputRequest();
498+
assertTrue(req.getAllowFreeform().isEmpty());
499+
500+
req.setAllowFreeform(true);
501+
assertTrue(req.getAllowFreeform().get());
502+
503+
req.setAllowFreeform(false);
504+
assertFalse(req.getAllowFreeform().get());
505+
}
506+
507+
// ── JSON deserialization into Optional-returning classes ───────────
508+
509+
@Test
510+
void jackson_deserializeSupportsWithFields() throws Exception {
511+
String json = "{\"vision\":true,\"reasoningEffort\":false}";
512+
var supports = MAPPER.readValue(json, ModelCapabilitiesOverride.Supports.class);
513+
assertTrue(supports.getVision().get());
514+
assertFalse(supports.getReasoningEffort().get());
515+
}
516+
517+
@Test
518+
void jackson_deserializeSupportsEmpty() throws Exception {
519+
String json = "{}";
520+
var supports = MAPPER.readValue(json, ModelCapabilitiesOverride.Supports.class);
521+
assertTrue(supports.getVision().isEmpty());
522+
assertTrue(supports.getReasoningEffort().isEmpty());
523+
}
524+
525+
@Test
526+
void jackson_deserializeLimitsWithFields() throws Exception {
527+
String json = "{\"max_prompt_tokens\":4096,\"max_output_tokens\":1024,\"max_context_window_tokens\":16384}";
528+
var limits = MAPPER.readValue(json, ModelCapabilitiesOverride.Limits.class);
529+
assertEquals(4096, limits.getMaxPromptTokens().getAsInt());
530+
assertEquals(1024, limits.getMaxOutputTokens().getAsInt());
531+
assertEquals(16384, limits.getMaxContextWindowTokens().getAsInt());
532+
}
533+
534+
@Test
535+
void jackson_deserializeLimitsEmpty() throws Exception {
536+
String json = "{}";
537+
var limits = MAPPER.readValue(json, ModelCapabilitiesOverride.Limits.class);
538+
assertTrue(limits.getMaxPromptTokens().isEmpty());
539+
assertTrue(limits.getMaxOutputTokens().isEmpty());
540+
assertTrue(limits.getMaxContextWindowTokens().isEmpty());
541+
}
542+
543+
@Test
544+
void jackson_deserializeInfiniteSessionConfigWithFields() throws Exception {
545+
String json = "{\"enabled\":true,\"backgroundCompactionThreshold\":0.7,\"bufferExhaustionThreshold\":0.9}";
546+
var cfg = MAPPER.readValue(json, InfiniteSessionConfig.class);
547+
assertTrue(cfg.getEnabled().get());
548+
assertEquals(0.7, cfg.getBackgroundCompactionThreshold().getAsDouble(), 0.001);
549+
assertEquals(0.9, cfg.getBufferExhaustionThreshold().getAsDouble(), 0.001);
550+
}
551+
552+
@Test
553+
void jackson_deserializeInfiniteSessionConfigEmpty() throws Exception {
554+
String json = "{}";
555+
var cfg = MAPPER.readValue(json, InfiniteSessionConfig.class);
556+
assertTrue(cfg.getEnabled().isEmpty());
557+
assertTrue(cfg.getBackgroundCompactionThreshold().isEmpty());
558+
assertTrue(cfg.getBufferExhaustionThreshold().isEmpty());
559+
}
560+
296561
// ── Jackson serialization roundtrip ───────────────────────────────
297562
//
298563
// Classes whose fields carry @JsonProperty (InfiniteSessionConfig,

0 commit comments

Comments
 (0)