TestSpec_PublicAPI_UpdateFieldInFrontmatter validates the documented frontmatter field update. Spec: "Sets a field in frontmatter YAML"
(t *testing.T)
| 353 | // TestSpec_PublicAPI_UpdateFieldInFrontmatter validates the documented frontmatter field update. |
| 354 | // Spec: "Sets a field in frontmatter YAML" |
| 355 | func TestSpec_PublicAPI_UpdateFieldInFrontmatter(t *testing.T) { |
| 356 | tests := []struct { |
| 357 | name string |
| 358 | content string |
| 359 | fieldName string |
| 360 | fieldValue string |
| 361 | wantErr bool |
| 362 | checkContains string |
| 363 | }{ |
| 364 | { |
| 365 | name: "updates existing field", |
| 366 | content: "---\ndescription: old description\n---\n\n# Content", |
| 367 | fieldName: "description", |
| 368 | fieldValue: "new description", |
| 369 | wantErr: false, |
| 370 | checkContains: "new description", |
| 371 | }, |
| 372 | { |
| 373 | name: "adds new field when absent", |
| 374 | content: "---\nengine: copilot\n---\n\n# Content", |
| 375 | fieldName: "description", |
| 376 | fieldValue: "my workflow", |
| 377 | wantErr: false, |
| 378 | checkContains: "my workflow", |
| 379 | }, |
| 380 | { |
| 381 | // SPEC_AMBIGUITY: The README spec says "Sets a field in frontmatter YAML" without |
| 382 | // specifying the error-path for content without frontmatter. The implementation |
| 383 | // creates a new frontmatter block in this case rather than returning an error. |
| 384 | name: "creates frontmatter when content has none", |
| 385 | content: "# Just markdown with no frontmatter", |
| 386 | fieldName: "description", |
| 387 | fieldValue: "value", |
| 388 | wantErr: false, |
| 389 | checkContains: "value", |
| 390 | }, |
| 391 | } |
| 392 | |
| 393 | for _, tt := range tests { |
| 394 | t.Run(tt.name, func(t *testing.T) { |
| 395 | result, err := cli.UpdateFieldInFrontmatter(tt.content, tt.fieldName, tt.fieldValue) |
| 396 | if tt.wantErr { |
| 397 | assert.Error(t, err, "UpdateFieldInFrontmatter should return error for %q", tt.name) |
| 398 | return |
| 399 | } |
| 400 | require.NoError(t, err, "UpdateFieldInFrontmatter should not error for %q", tt.name) |
| 401 | assert.Contains(t, result, tt.checkContains, "result should contain updated value for %q", tt.name) |
| 402 | }) |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // TestSpec_PublicAPI_SetFieldInOnTrigger validates the documented on: trigger field update. |
| 407 | // Spec: "Sets a field inside the on: trigger block" |
nothing calls this directly
no test coverage detected