11import { describe , expect , test } from "bun:test" ;
2- import { pinOf , resolveLiveDeployments , sameSource } from "./deployment.js" ;
2+ import { resolveLiveDeployments } from "./deployment.js" ;
33
44const TENANT_ID = "tnt_acme" ;
5- const SOURCE = { kind : "asset" , assetId : "ast_triage" , package : { format : "source" , commitSha : "c0ffee" , packageName : "@corbits/pr-triage-workflow" } } ;
6- const SPEC = {
7- anchorRunId : "run_old" ,
8- deploymentDomain : "acme.test" ,
9- sourceAuthorityPrincipalId : "prn_deployer" ,
10- sourceOfferingIds : [ "off_a" , "off_b" ] ,
11- defaultSourceOfferingId : "off_a" ,
12- deployContent : { systemPrompt : "Triage pull requests." } ,
13- frozenApprovalBundle : { source : SOURCE , entry : "./pr-triage.mjs" } ,
14- } ;
15-
16- const TARBALL_SOURCE = { kind : "asset" , assetId : "ast_corbits" , package : { format : "tarball" } } ;
17-
18- function closurePinning ( ...topLevel : { name : string ; version : string } [ ] ) {
19- const entries = topLevel . map ( ( { name, version } ) => ( {
20- name,
21- version,
22- source : { ...TARBALL_SOURCE , package : { format : "tarball" , path : `tarballs/${ name . slice ( 1 ) . replace ( "/" , "-" ) } -${ version } .tgz` , integrity : "sha512-AAAA" } } ,
23- } ) ) ;
24- return { schemaVersion : "1" , topLevel, entries } as never ;
25- }
26-
27- function tarballSpec ( version : string ) {
28- return {
29- ...SPEC ,
30- frozenApprovalBundle : {
31- source : TARBALL_SOURCE ,
32- entry : "./pr-triage.mjs" ,
33- closure : closurePinning ( { name : "@corbits/pr-triage-workflow" , version } ) ,
34- } ,
35- } ;
36- }
37-
385function selectReturning ( rows : unknown [ ] ) {
396 const chain = {
407 from : ( ) => chain ,
@@ -47,38 +14,15 @@ function selectReturning(rows: unknown[]) {
4714}
4815
4916describe ( "deployments" , ( ) => {
50- test ( "two deployments run the same source only when asset, commit and entry match" , async ( ) => {
51- const moved = { ...SPEC , frozenApprovalBundle : { ...SPEC . frozenApprovalBundle , source : { ...SOURCE , package : { ...SOURCE . package , commitSha : "beef" } } } } ;
52- const specs : Record < string , unknown > = { run_a : SPEC , run_b : SPEC , run_moved : moved } ;
53- const launchSpecs = { get : async ( anchorRunId : string ) => ( specs [ anchorRunId ] ?? null ) as never } ;
54- expect ( await sameSource ( launchSpecs , "run_a" , "run_b" ) ) . toBe ( true ) ;
55- expect ( await sameSource ( launchSpecs , "run_a" , "run_moved" ) ) . toBe ( false ) ;
56- expect ( await sameSource ( launchSpecs , "run_a" , "run_missing" ) ) . toBe ( false ) ;
57- } ) ;
58-
59- test ( "tarball-sourced deployments with different pins are not the same source" , async ( ) => {
60- const specs : Record < string , unknown > = { run_a : tarballSpec ( "0.1.0-a" ) , run_b : tarballSpec ( "0.1.0-a" ) , run_bumped : tarballSpec ( "0.1.0-b" ) } ;
61- const launchSpecs = { get : async ( anchorRunId : string ) => ( specs [ anchorRunId ] ?? null ) as never } ;
62- expect ( await sameSource ( launchSpecs , "run_a" , "run_b" ) ) . toBe ( true ) ;
63- expect ( await sameSource ( launchSpecs , "run_a" , "run_bumped" ) ) . toBe ( false ) ;
64- } ) ;
65-
6617 test ( "a deployment whose cancellation was requested is listed as cancelling" , async ( ) => {
6718 const createdAt = new Date ( "2026-10-07T12:00:00.000Z" ) ;
6819 const db = selectReturning ( [
69- { runId : "run_new" , workflow : "pr- triage" , domain : "acme.test" , createdAt, cancellationRequestedAt : null } ,
70- { runId : "run_old" , workflow : "pr- triage" , domain : "acme.test" , createdAt, cancellationRequestedAt : createdAt } ,
20+ { runId : "run_new" , workflow : "triage-listener-github " , domain : "acme.test" , createdAt, cancellationRequestedAt : null } ,
21+ { runId : "run_old" , workflow : "triage-listener-github " , domain : "acme.test" , createdAt, cancellationRequestedAt : createdAt } ,
7122 ] ) ;
72- expect ( await resolveLiveDeployments ( db , TENANT_ID , "pr- triage" ) ) . toEqual ( [
73- { runId : "run_new" , address : "run_new@acme.test" , createdAt, cancelling : false , workflow : "pr- triage" } ,
74- { runId : "run_old" , address : "run_old@acme.test" , createdAt, cancelling : true , workflow : "pr- triage" } ,
23+ expect ( await resolveLiveDeployments ( db , TENANT_ID , "triage-listener-github " ) ) . toEqual ( [
24+ { runId : "run_new" , address : "run_new@acme.test" , createdAt, cancelling : false , workflow : "triage-listener-github " } ,
25+ { runId : "run_old" , address : "run_old@acme.test" , createdAt, cancelling : true , workflow : "triage-listener-github " } ,
7526 ] ) ;
7627 } ) ;
7728} ) ;
78-
79- describe ( "pinOf" , ( ) => {
80- test ( "pins the frozen closure's one top-level package, and refuses a closure without one" , ( ) => {
81- expect ( pinOf ( closurePinning ( { name : "@corbits/pr-triage-workflow" , version : "0.1.0-a" } ) ) ) . toBe ( "@corbits/pr-triage-workflow@0.1.0-a" ) ;
82- expect ( ( ) => pinOf ( closurePinning ( ) ) ) . toThrow ( "frozen closure has 0 top-level packages, expected one" ) ;
83- } ) ;
84- } ) ;
0 commit comments