Repository navigation
Commit 0783eb0
fix(generate): scope a contract endpoint's package to its declared surface (#991)
`codefly generate contracts` refuses a service whose owned proto tree carries
both its served API and a client facade for another service's API:
proto declares services in multiple packages
[saas.accounts.v1 saas.policylog.v1]; a contract endpoint must be
single-package
The contract is in fact single-package. The facade is there because the service
CALLS that API and needs generated stubs, so the proto has to sit in the owned
tree for codegen to reach it — `--path saas`, with vendored imports excluded as
import-only. But the service serves none of it, and serviceContractPackage
derived the package purely by walking the proto tree, so a package the endpoint
does not serve made a well-formed endpoint look multi-package and the export
failed.
The answer was already on disk and unread. cli#947 gave a module the
CLI-owned contracts.codefly.yaml, whose `surfaces` name a per-endpoint
inventory of the services each endpoint actually serves, and
writeBuiltProtobufContract already receives that endpoint's surface in order to
fill the catalog's `services[]`. It just never reached the package derivation.
It does now: when a surface is declared, candidate packages are scoped to the
ones its services' fully-qualified names carry.
Deliberately unchanged in two directions, because a fix to a refusal must not
become a way past it:
- A module that declares NO surface narrows nothing. The single-package rule
stands exactly as before, which is what keeps the default honest for a
service that has no reason to carry a foreign package.
- A surface that names no package the descriptor set declares a service in
narrows nothing either. That is a configuration error, and the existing
unscoped diagnostics describe it far better than a silently empty contract
would.
The copied proto sources are untouched: the descriptor set spans the whole owned
tree and the sources copy with it, as it already does for message-only packages.
Narrowing what gets copied is a separate question from which package the
endpoint's contract reports.
Found from module-saas-starter#1067, where accounts consumes a policy-log
witness (`policylogv1.WitnessServiceClient`) and `generate contracts --check`
refused the tree. Verified against that exact tree with a locally built binary:
before, the multi-package refusal; after, it proceeds and reports ordinary
drift — `run codefly generate contracts to update` — which is what --check
should say for a tree whose contracts have not been regenerated yet.
Tests: three cases in TestServiceContractPackage — a facade in a foreign package
scoped away by its surface (and still refused without one, so the rule is scoped
by a declaration rather than removed), a surface naming an absent package
falling back to the unscoped diagnostics, and a surface whose service name
carries no package qualifier narrowing nothing. Mutation-verified: emptying the
scoping set reds the first. `go test ./cmd/generate/` passes, `go build ./...`
and `go vet` clean. docs/commands.md records the behaviour in the
contracts.codefly.yaml section.
Co-authored-by: Codefly Automation <312536060+antoinetoussaint-byte@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent a9e467b commit 0783eb0
3 files changed
Lines changed: 126 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
385 | | - | |
| 386 | + | |
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
| |||
422 | 423 | | |
423 | 424 | | |
424 | 425 | | |
425 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
426 | 438 | | |
427 | 439 | | |
428 | 440 | | |
| |||
462 | 474 | | |
463 | 475 | | |
464 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
465 | 494 | | |
466 | 495 | | |
467 | 496 | | |
| |||
481 | 510 | | |
482 | 511 | | |
483 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
484 | 528 | | |
485 | 529 | | |
486 | 530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
547 | 554 | | |
548 | 555 | | |
549 | 556 | | |
| |||
568 | 575 | | |
569 | 576 | | |
570 | 577 | | |
571 | | - | |
| 578 | + | |
572 | 579 | | |
573 | 580 | | |
574 | 581 | | |
| |||
582 | 589 | | |
583 | 590 | | |
584 | 591 | | |
585 | | - | |
| 592 | + | |
586 | 593 | | |
587 | 594 | | |
588 | 595 | | |
| |||
592 | 599 | | |
593 | 600 | | |
594 | 601 | | |
595 | | - | |
| 602 | + | |
596 | 603 | | |
597 | 604 | | |
598 | 605 | | |
599 | 606 | | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
600 | 663 | | |
601 | 664 | | |
602 | 665 | | |
| |||
605 | 668 | | |
606 | 669 | | |
607 | 670 | | |
608 | | - | |
| 671 | + | |
609 | 672 | | |
610 | 673 | | |
611 | 674 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2772 | 2772 | | |
2773 | 2773 | | |
2774 | 2774 | | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
2775 | 2787 | | |
2776 | 2788 | | |
2777 | 2789 | | |
| |||
0 commit comments