-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: /app-config returns valid devflags
Suppose we have the following scenario: DEFAULT_DEVFLAGS = { a: {} } DB overrides = { a: { b: true } } When the server starts, DEVFLAGS and /app-config have the same data: DEVFLAGS = { a: { b: true } } /app-config returns { a: { b : true } } While the server is still running, if the DB override are changed: DB overrides = { a: { c: true } } The expected data is: DEVFLAGS = { a: { b: true } } /app-config returns { a: { c: true } } However, the bug is that /app-config will merge based on the current DEVFLAGS: /app-config returns { a: { b: true, c: true } } This commit ensures overrides are merged from DEFAULT_DEVFLAGS. Change-Id: I88a3c8db646b37eb3be7355c3d3a8993bea5ad59 GitOrigin-RevId: 72c263a3aec874d54f6617a1735125e3fa644c9f
- Loading branch information
1 parent
112b4c3
commit fbcf211
Showing
9 changed files
with
184 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { mergeSane } from "@/wab/shared/common"; | ||
import { DEVFLAGS } from "@/wab/shared/devflags"; | ||
import { DbMgr } from "@/wab/server/db/DbMgr"; | ||
import { | ||
applyDevFlagOverridesToDefaults, | ||
DevFlagsType, | ||
} from "@/wab/shared/devflags"; | ||
|
||
/** | ||
* WARNING: This function may return devflags inconsistent with the DEVFLAGS. | ||
* DEVFLAGS is only computed once, when the server starts. | ||
* If an override is submitted after the server starts, this function will | ||
* include the new overrides, while DEVFLAGS will stay the same. | ||
*/ | ||
export async function getDevFlagsMergedWithOverrides( | ||
mgr: DbMgr | ||
): Promise<typeof DEVFLAGS> { | ||
): Promise<DevFlagsType> { | ||
const overrides = await mgr.tryGetDevFlagOverrides(); | ||
const merged = mergeSane({}, DEVFLAGS, JSON.parse(overrides?.data ?? "{}")); | ||
return merged; | ||
return applyDevFlagOverridesToDefaults(JSON.parse(overrides?.data ?? "{}")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { applyDevFlagOverrides, DEVFLAGS } from "@/wab/shared/devflags"; | ||
import { MigrationDbMgr } from "@/wab/server/db/BundleMigrator"; | ||
import { applyDevFlagOverrides } from "@/wab/shared/devflags"; | ||
|
||
export async function ensureDevFlags(dbMgr: MigrationDbMgr) { | ||
const devflags = await dbMgr.tryGetDevFlagOverrides(); | ||
if (devflags) { | ||
applyDevFlagOverrides(DEVFLAGS, JSON.parse(devflags.data)); | ||
applyDevFlagOverrides(JSON.parse(devflags.data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { | ||
applyDevFlagOverrides, | ||
applyDevFlagOverridesToDefaults, | ||
applyDevFlagOverridesToTarget, | ||
DEVFLAGS, | ||
DevFlagsType, | ||
} from "@/wab/shared/devflags"; | ||
|
||
describe("devflags", () => { | ||
describe("applyDevFlagOverridesToTarget", () => { | ||
it("merges objects properly", () => { | ||
const devflags = { | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
visibility: false, | ||
typography: false, | ||
}, | ||
}, | ||
} as DevFlagsType; | ||
|
||
applyDevFlagOverridesToTarget(devflags, { | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
visibility: true, | ||
}, | ||
}, | ||
}); | ||
expect( | ||
devflags.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(true); | ||
expect( | ||
devflags.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(false); | ||
|
||
applyDevFlagOverridesToTarget(devflags, { | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
typography: true, | ||
}, | ||
}, | ||
}); | ||
expect( | ||
devflags.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(true); | ||
expect( | ||
devflags.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(true); | ||
}); | ||
}); | ||
|
||
describe("applyDevFlagOverridesToDefaults", () => { | ||
it("merges from default devflags", () => { | ||
const devflags1 = applyDevFlagOverridesToDefaults({ | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
visibility: true, | ||
}, | ||
}, | ||
}); | ||
expect( | ||
devflags1.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(true); | ||
expect( | ||
devflags1.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(false); | ||
|
||
const devflags2 = applyDevFlagOverridesToDefaults({ | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
typography: true, | ||
}, | ||
}, | ||
}); | ||
expect( | ||
devflags2.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(false); | ||
expect( | ||
devflags2.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(true); | ||
}); | ||
}); | ||
|
||
describe("applyDevFlagOverrides", () => { | ||
it("merges from default devflags", () => { | ||
expect( | ||
DEVFLAGS.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(false); | ||
expect( | ||
DEVFLAGS.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(false); | ||
|
||
applyDevFlagOverrides({ | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
visibility: true, | ||
}, | ||
}, | ||
}); | ||
expect( | ||
DEVFLAGS.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(true); | ||
expect( | ||
DEVFLAGS.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(false); | ||
|
||
applyDevFlagOverrides({ | ||
defaultContentCreatorConfig: { | ||
styleSectionVisibilities: { | ||
typography: true, | ||
}, | ||
}, | ||
}); | ||
expect( | ||
DEVFLAGS.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.visibility | ||
).toBe(false); | ||
expect( | ||
DEVFLAGS.defaultContentCreatorConfig.styleSectionVisibilities | ||
?.typography | ||
).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters