@@ -8,7 +8,6 @@ import { tmpdir } from "node:os";
88import { join } from "node:path" ;
99import { fileURLToPath } from "node:url" ;
1010import { $transaction } from "~/db.server" ;
11- import { FeatureFlagCatalog , FEATURE_FLAG } from "~/v3/featureFlags" ;
1211import { createDeploymentWithNextVersion } from "~/v3/services/initializeDeployment/createDeploymentWithNextVersion.server" ;
1312import {
1413 PreviewAutoArchivePolicy ,
@@ -23,82 +22,9 @@ import {
2322 processPreviewAutoArchivePage ,
2423 previewAutoArchiveCount ,
2524 savePreviewAutoArchivePolicy ,
26- isPreviewAutoArchiveEnabled ,
2725 previewBranchActivity ,
2826} from "./previewAutoArchive.server" ;
2927
30- postgresTest (
31- "rollout defaults off with organization overrides over the global flag" ,
32- async ( { prisma } ) => {
33- const key = FEATURE_FLAG . previewAutoArchiveEnabled ;
34- expect ( FeatureFlagCatalog [ key ] . safeParse ( "false" ) . success ) . toBe ( false ) ;
35- expect ( await isPreviewAutoArchiveEnabled ( prisma , null ) ) . toBe ( false ) ;
36- expect ( await isPreviewAutoArchiveEnabled ( prisma , { [ key ] : true } ) ) . toBe ( true ) ;
37- await prisma . featureFlag . create ( { data : { key, value : true } } ) ;
38- expect ( await isPreviewAutoArchiveEnabled ( prisma , null ) ) . toBe ( true ) ;
39- expect ( await isPreviewAutoArchiveEnabled ( prisma , { [ key ] : false } ) ) . toBe ( false ) ;
40- await prisma . featureFlag . update ( { where : { key } , data : { value : false } } ) ;
41- expect ( await isPreviewAutoArchiveEnabled ( prisma , null ) ) . toBe ( false ) ;
42- expect ( await isPreviewAutoArchiveEnabled ( prisma , { [ key ] : true } ) ) . toBe ( true ) ;
43- }
44- ) ;
45-
46- postgresTest (
47- "disabled rollout preserves configured policies and resumes when globally enabled" ,
48- async ( { prisma } ) => {
49- const { parent, branch } = await seed ( prisma , false ) ;
50- const candidate = await branch ( ) ;
51- const page = await processPreviewAutoArchivePage ( prisma , 0 , now ) ;
52- expect ( page ) . toMatchObject ( { scanned : 0 , archived : [ ] } ) ;
53- const paused = await prisma . runtimeEnvironment . findFirstOrThrow ( { where : { id : parent . id } } ) ;
54- expect ( paused . previewAutoArchiveAfterDays ) . toBe ( 14 ) ;
55- expect ( paused . previewAutoArchiveNextCheckAt ) . toEqual ( new Date ( now . getTime ( ) + 3_600_000 ) ) ;
56- await prisma . featureFlag . create ( {
57- data : { key : FEATURE_FLAG . previewAutoArchiveEnabled , value : true } ,
58- } ) ;
59- const resumed = await processPreviewAutoArchivePage (
60- prisma ,
61- 0 ,
62- paused . previewAutoArchiveNextCheckAt !
63- ) ;
64- expect ( resumed ?. archived . map ( ( { id } ) => id ) ) . toEqual ( [ candidate . id ] ) ;
65- }
66- ) ;
67-
68- postgresTest (
69- "revoking rollout between pages pauses without losing the cursor" ,
70- async ( { prisma } ) => {
71- const { parent, organization, branch } = await seed ( prisma ) ;
72- for ( let i = 0 ; i < 101 ; i ++ ) await branch ( ) ;
73- expect ( ( await processPreviewAutoArchivePage ( prisma , 0 , now ) ) ?. archived ) . toHaveLength ( 100 ) ;
74- const before = await prisma . runtimeEnvironment . findFirstOrThrow ( { where : { id : parent . id } } ) ;
75- await prisma . organization . update ( {
76- where : { id : organization . id } ,
77- data : { featureFlags : { previewAutoArchiveEnabled : false } } ,
78- } ) ;
79- await prisma . featureFlag . create ( {
80- data : { key : FEATURE_FLAG . previewAutoArchiveEnabled , value : true } ,
81- } ) ;
82- expect ( await processPreviewAutoArchivePage ( prisma , 0 , now ) ) . toMatchObject ( {
83- scanned : 0 ,
84- archived : [ ] ,
85- } ) ;
86- const paused = await prisma . runtimeEnvironment . findFirstOrThrow ( { where : { id : parent . id } } ) ;
87- expect ( paused . previewAutoArchiveCursorId ) . toBe ( before . previewAutoArchiveCursorId ) ;
88- expect ( paused . previewAutoArchiveCursorCreatedAt ) . toEqual (
89- before . previewAutoArchiveCursorCreatedAt
90- ) ;
91- await prisma . organization . update ( {
92- where : { id : organization . id } ,
93- data : { featureFlags : { } } ,
94- } ) ;
95- expect (
96- ( await processPreviewAutoArchivePage ( prisma , 0 , paused . previewAutoArchiveNextCheckAt ! ) )
97- ?. archived
98- ) . toHaveLength ( 1 ) ;
99- }
100- ) ;
101-
10228const archiveGuard = {
10329 archiveGuard : {
10430 type : "PREVIEW" as const ,
@@ -373,43 +299,6 @@ postgresTest(
373299 }
374300) ;
375301
376- postgresTest (
377- "flag enabled during deployment preparation cannot bypass the archive lock" ,
378- async ( { prisma } ) => {
379- const { branch, deployData, project } = await seed ( prisma , false ) ;
380- await prisma . organization . update ( {
381- where : { id : project . organizationId } ,
382- data : { featureFlags : { previewAutoArchiveEnabled : false } } ,
383- } ) ;
384- const candidate = await branch ( ) ;
385- const preparing = barrier ( ) ;
386- const resume = barrier ( ) ;
387- const deploying = createDeploymentWithNextVersion (
388- prisma ,
389- candidate . id ,
390- async ( ) => {
391- preparing . release ( ) ;
392- await resume . promise ;
393- return deployData ( ) ;
394- } ,
395- archiveGuard
396- ) ;
397- const rejected = expect ( deploying ) . rejects . toMatchObject ( { status : 409 } ) ;
398- await preparing . promise ;
399- try {
400- await prisma . organization . update ( {
401- where : { id : project . organizationId } ,
402- data : { featureFlags : { previewAutoArchiveEnabled : true } } ,
403- } ) ;
404- expect ( ( await processPreviewAutoArchivePage ( prisma , 0 , now ) ) ?. archived ) . toHaveLength ( 1 ) ;
405- } finally {
406- resume . release ( ) ;
407- }
408- await rejected ;
409- expect ( await prisma . workerDeployment . count ( { where : { environmentId : candidate . id } } ) ) . toBe ( 0 ) ;
410- }
411- ) ;
412-
413302postgresTest (
414303 "a policy update owns the root and prevents cleanup using an outdated policy" ,
415304 async ( { prisma } ) => {
0 commit comments