MCPcopy Create free account
hub / github.com/github/gh-aw / TestTokenWeightsSingleQuoteEscapingInYAML

Function TestTokenWeightsSingleQuoteEscapingInYAML

pkg/workflow/engine_test.go:518–555  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

516}
517
518func TestTokenWeightsSingleQuoteEscapingInYAML(t *testing.T) {
519 compiler := NewCompiler()
520 registry := GetGlobalEngineRegistry()
521 engine, err := registry.GetEngine("claude")
522 if err != nil {
523 t.Fatalf("Failed to get claude engine: %v", err)
524 }
525
526 // Model name containing a single quote — must not break YAML single-quoted scalar
527 workflowData := &WorkflowData{
528 Name: "Test Workflow",
529 EngineConfig: &EngineConfig{
530 ID: "claude",
531 TokenWeights: &types.TokenWeights{
532 Multipliers: map[string]float64{
533 "bob's-model": 2.0, // Single quote in key
534 },
535 },
536 },
537 }
538
539 var out strings.Builder
540 compiler.generateCreateAwInfo(&out, workflowData, engine)
541 output := out.String()
542
543 // The generated YAML must not contain an un-escaped single quote inside a single-quoted value.
544 // In YAML, a single quote inside a single-quoted scalar is represented as ”.
545 if !strings.Contains(output, "GH_AW_INFO_TOKEN_WEIGHTS") {
546 t.Errorf("Expected GH_AW_INFO_TOKEN_WEIGHTS in YAML output when multipliers are configured, got:\n%s", output)
547 }
548 if !strings.Contains(output, "bob''s-model") {
549 t.Errorf("Expected single quote to be escaped as '' in YAML output, got:\n%s", output)
550 }
551 // There must be no dangling unescaped single quote inside the GH_AW_INFO_TOKEN_WEIGHTS value
552 if strings.Contains(output, "bob's-model") {
553 t.Errorf("Unescaped single quote found in YAML output:\n%s", output)
554 }
555}
556
557func TestTokenWeightsEnvOmittedWhenOnlyTokenClassWeightsConfigured(t *testing.T) {
558 compiler := NewCompiler()

Callers

nothing calls this directly

Calls 6

generateCreateAwInfoMethod · 0.95
NewCompilerFunction · 0.85
GetGlobalEngineRegistryFunction · 0.85
GetEngineMethod · 0.80
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected