@@ -6,11 +6,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
66// addDomainToCompose reads the compose file from disk through loadDockerCompose
77// (existsSync + readFileSync). Mock node:fs so the function runs its real
88// label-generation logic against an in-memory compose spec.
9- const composeYaml = `
9+ const baseComposeYaml = `
1010services:
1111 frigate:
1212 image: frigate
1313` ;
14+ let composeYaml = baseComposeYaml ;
1415
1516vi . mock ( "node:fs" , async ( importOriginal ) => {
1617 const actual = await importOriginal < typeof import ( "node:fs" ) > ( ) ;
@@ -62,6 +63,7 @@ const serviceLabels = (
6263describe ( "addDomainToCompose enabled filtering" , ( ) => {
6364 beforeEach ( ( ) => {
6465 vi . clearAllMocks ( ) ;
66+ composeYaml = baseComposeYaml ;
6567 } ) ;
6668
6769 it ( "generates traefik labels for an enabled domain" , async ( ) => {
@@ -88,6 +90,55 @@ describe("addDomainToCompose enabled filtering", () => {
8890 ) ;
8991 } ) ;
9092
93+ it . each ( [
94+ [
95+ "docker-compose" ,
96+ `services:
97+ frigate:
98+ image: frigate
99+ labels:
100+ - traefik.enable=true
101+ - traefik.http.routers.test-app-1-web.rule=Host(\`frigate.example.com\`)
102+ - traefik.http.services.test-app-1-web.loadbalancer.server.port=8971
103+ - traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes=/api
104+ - custom.label=preserved
105+ ` ,
106+ ] ,
107+ [
108+ "stack" ,
109+ `services:
110+ frigate:
111+ image: frigate
112+ deploy:
113+ labels:
114+ - traefik.enable=true
115+ - traefik.http.routers.test-app-1-web.rule=Host(\`frigate.example.com\`)
116+ - traefik.http.services.test-app-1-web.loadbalancer.server.port=8971
117+ - traefik.http.middlewares.stripprefix-test-app-1.stripprefix.prefixes=/api
118+ - custom.label=preserved
119+ ` ,
120+ ] ,
121+ ] as const ) (
122+ "removes stale labels for a disabled domain from %s rebuilds" ,
123+ async ( composeType , staleComposeYaml ) => {
124+ composeYaml = staleComposeYaml ;
125+
126+ const result = await addDomainToCompose ( { ...baseCompose , composeType } , [
127+ { ...baseDomain , enabled : false } ,
128+ ] ) ;
129+
130+ const service = result ?. services ?. frigate ;
131+ const labels =
132+ composeType === "docker-compose"
133+ ? service ?. labels
134+ : service ?. deploy ?. labels ;
135+ expect ( labels ) . toContain ( "custom.label=preserved" ) ;
136+ expect (
137+ ( labels as string [ ] ) . some ( ( label ) => label . includes ( "test-app-1" ) ) ,
138+ ) . toBe ( false ) ;
139+ } ,
140+ ) ;
141+
91142 it ( "emits labels only for the enabled domain when both are present" , async ( ) => {
92143 const result = await addDomainToCompose ( baseCompose , [
93144 { ...baseDomain , host : "enabled.example.com" , enabled : true } ,
0 commit comments