History

Merge remote-tracking branch 'origin/codex/effect-lint-openapi-plugin-tests' into codex/effect-lint-integration

Rhys Sullivan committed 6 months ago

Commit eb2f5a42 parents 60627a9 2cae07e1 file · +25 −23Browse files

Unified · Split

packages/plugins/openapi/src/sdk/plugin.test.ts+25−23
@@ -1,5 +1,5 @@
1import { expect, layer } from "@effect/vitest";1import { expect, layer } from "@effect/vitest";
2import { Effect, Layer, Schema } from "effect";2import { Effect, Layer, Predicate, Schema } from "effect";
3import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi";3import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi";
4import { HttpClient, HttpRouter, HttpServerRequest } from "effect/unstable/http";4import { HttpClient, HttpRouter, HttpServerRequest } from "effect/unstable/http";
5import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";5import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
@@ -373,8 +373,10 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 367 unmodified lines
373 executor.tools.invoke("noauth.items.listItems", {}, autoApprove),373 executor.tools.invoke("noauth.items.listItems", {}, autoApprove),
374 );374 );
375 375
376 expect((error as { _tag: string })._tag).toBe("ToolInvocationError");376 expect(Predicate.isTagged(error, "ToolInvocationError")).toBe(true);
377 expect((error as { message: string }).message).toContain("missing-token");377 expect(error).toMatchObject({
378 message: expect.stringContaining("missing-token"),
379 });
378 }),380 }),
379 );381 );
380 382
@@ -606,7 +608,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 225 unmodified lines
606 // Org-level base source608 // Org-level base source
607 yield* executor.openapi.addSpec({609 yield* executor.openapi.addSpec({
608 spec: specJson,610 spec: specJson,
609 scope: ORG_SCOPE as string,611 scope: String(ORG_SCOPE),
610 namespace: "shared",612 namespace: "shared",
611 baseUrl: "",613 baseUrl: "",
612 name: "Org Source",614 name: "Org Source",
@@ -615,20 +617,20 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 2 unmodified lines
615 // Per-user shadow with the same namespace617 // Per-user shadow with the same namespace
616 yield* executor.openapi.addSpec({618 yield* executor.openapi.addSpec({
617 spec: specJson,619 spec: specJson,
618 scope: USER_SCOPE as string,620 scope: String(USER_SCOPE),
619 namespace: "shared",621 namespace: "shared",
620 name: "User Source",622 name: "User Source",
621 });623 });
622 624
623 const userView = yield* executor.openapi.getSource("shared", USER_SCOPE as string);625 const userView = yield* executor.openapi.getSource("shared", String(USER_SCOPE));
624 const orgView = yield* executor.openapi.getSource("shared", ORG_SCOPE as string);626 const orgView = yield* executor.openapi.getSource("shared", String(ORG_SCOPE));
625 627
626 // Both rows must coexist — innermost-wins reads come from the628 // Both rows must coexist — innermost-wins reads come from the
627 // executor; the store's scope-pinned getters return the exact row.629 // executor; the store's scope-pinned getters return the exact row.
628 expect(userView?.name).toBe("User Source");630 expect(userView?.name).toBe("User Source");
629 expect(userView?.scope).toBe(USER_SCOPE as string);631 expect(userView?.scope).toBe(String(USER_SCOPE));
630 expect(orgView?.name).toBe("Org Source");632 expect(orgView?.name).toBe("Org Source");
631 expect(orgView?.scope).toBe(ORG_SCOPE as string);633 expect(orgView?.scope).toBe(String(ORG_SCOPE));
632 }),634 }),
633 );635 );
634 636
@@ -652,20 +654,20 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 17 unmodified lines
652 654
653 yield* executor.openapi.addSpec({655 yield* executor.openapi.addSpec({
654 spec: specJson,656 spec: specJson,
655 scope: ORG_SCOPE as string,657 scope: String(ORG_SCOPE),
656 namespace: "shared",658 namespace: "shared",
657 baseUrl: "https://org.example.com",659 baseUrl: "https://org.example.com",
658 name: "Org Source",660 name: "Org Source",
659 });661 });
660 yield* executor.openapi.addSpec({662 yield* executor.openapi.addSpec({
661 spec: specJson,663 spec: specJson,
662 scope: USER_SCOPE as string,664 scope: String(USER_SCOPE),
663 namespace: "shared",665 namespace: "shared",
664 name: "User Source",666 name: "User Source",
665 });667 });
666 668
667 findManyCalls.length = 0;669 findManyCalls.length = 0;
668 const userView = yield* executor.openapi.getSource("shared", USER_SCOPE as string);670 const userView = yield* executor.openapi.getSource("shared", String(USER_SCOPE));
669 671
670 expect(userView?.config.baseUrl).toBe("https://org.example.com");672 expect(userView?.config.baseUrl).toBe("https://org.example.com");
671 expect(findManyCalls.some((call) => call.model === "openapi_source")).toBe(false);673 expect(findManyCalls.some((call) => call.model === "openapi_source")).toBe(false);
@@ -689,23 +691,23 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 17 unmodified lines
689 691
690 yield* executor.openapi.addSpec({692 yield* executor.openapi.addSpec({
691 spec: specJson,693 spec: specJson,
692 scope: ORG_SCOPE as string,694 scope: String(ORG_SCOPE),
693 namespace: "shared",695 namespace: "shared",
694 baseUrl: "",696 baseUrl: "",
695 name: "Org Source",697 name: "Org Source",
696 });698 });
697 yield* executor.openapi.addSpec({699 yield* executor.openapi.addSpec({
698 spec: specJson,700 spec: specJson,
699 scope: USER_SCOPE as string,701 scope: String(USER_SCOPE),
700 namespace: "shared",702 namespace: "shared",
701 baseUrl: "",703 baseUrl: "",
702 name: "User Source",704 name: "User Source",
703 });705 });
704 706
705 yield* executor.openapi.removeSpec("shared", USER_SCOPE as string);707 yield* executor.openapi.removeSpec("shared", String(USER_SCOPE));
706 708
707 const userView = yield* executor.openapi.getSource("shared", USER_SCOPE as string);709 const userView = yield* executor.openapi.getSource("shared", String(USER_SCOPE));
708 const orgView = yield* executor.openapi.getSource("shared", ORG_SCOPE as string);710 const orgView = yield* executor.openapi.getSource("shared", String(ORG_SCOPE));
709 711
710 expect(userView).toBeNull();712 expect(userView).toBeNull();
711 expect(orgView?.name).toBe("Org Source");713 expect(orgView?.name).toBe("Org Source");
@@ -729,26 +731,26 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 17 unmodified lines
729 731
730 yield* executor.openapi.addSpec({732 yield* executor.openapi.addSpec({
731 spec: specJson,733 spec: specJson,
732 scope: ORG_SCOPE as string,734 scope: String(ORG_SCOPE),
733 namespace: "shared",735 namespace: "shared",
734 baseUrl: "https://org.example.com",736 baseUrl: "https://org.example.com",
735 name: "Org Source",737 name: "Org Source",
736 });738 });
737 yield* executor.openapi.addSpec({739 yield* executor.openapi.addSpec({
738 spec: specJson,740 spec: specJson,
739 scope: USER_SCOPE as string,741 scope: String(USER_SCOPE),
740 namespace: "shared",742 namespace: "shared",
741 baseUrl: "https://user.example.com",743 baseUrl: "https://user.example.com",
742 name: "User Source",744 name: "User Source",
743 });745 });
744 746
745 yield* executor.openapi.updateSource("shared", USER_SCOPE as string, {747 yield* executor.openapi.updateSource("shared", String(USER_SCOPE), {
746 name: "User Renamed",748 name: "User Renamed",
747 baseUrl: "https://user-new.example.com",749 baseUrl: "https://user-new.example.com",
748 });750 });
749 751
750 const userView = yield* executor.openapi.getSource("shared", USER_SCOPE as string);752 const userView = yield* executor.openapi.getSource("shared", String(USER_SCOPE));
751 const orgView = yield* executor.openapi.getSource("shared", ORG_SCOPE as string);753 const orgView = yield* executor.openapi.getSource("shared", String(ORG_SCOPE));
752 754
753 expect(userView?.name).toBe("User Renamed");755 expect(userView?.name).toBe("User Renamed");
754 expect(userView?.config.baseUrl).toBe("https://user-new.example.com");756 expect(userView?.config.baseUrl).toBe("https://user-new.example.com");
@@ -939,7 +941,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 184 unmodified lines
939 const failure = yield* executor.secrets941 const failure = yield* executor.secrets
940 .remove(SecretId.make("locked"))942 .remove(SecretId.make("locked"))
941 .pipe(Effect.flip);943 .pipe(Effect.flip);
942 expect((failure as { _tag: string })._tag).toBe("SecretInUseError");944 expect(Predicate.isTagged(failure, "SecretInUseError")).toBe(true);
943 945
944 // Detach the binding, then remove succeeds.946 // Detach the binding, then remove succeeds.
945 yield* executor.openapi.removeSourceBinding(947 yield* executor.openapi.removeSourceBinding(