@ogygia/flags
QA overrides
Force a flag's variant from the URL with ?og-exp=name:variant to check each branch by hand. It works on the dev server out of the box, and in production only for requests you allow.
On this page
To check a variant by hand, you shouldn’t have to find a visitor id that hashes into it. Add og-exp to the page’s address and the flag answers what you asked for, ahead of everything else, stickiness included.
/pricing?og-exp=hero:bold
/?og-exp=hero:bold,new-checkout:on
/?og-exp=hero:bold&og-exp=search:semanticSyntax
Each override is name:variant. Several go in one og-exp parameter separated by commas, or in several og-exp parameters. A boolean flag takes on or off. A variant the flag doesn’t declare is ignored, and the flag decides as if there were no override, so a typo never invents a bucket.
The override is read on every request, from that request’s URL. It doesn’t stick: the next page without the parameter decides normally, so carry the parameter along while you test, or use a cookie-based gate as below.
An override is an ordinary decision for everything downstream. The page renders the variant, the read marks the render per visitor, a federation mount carries it, and it sends an exposure, so QA traffic shows up in your analytics unless you filter it.
Production
By default, every request on the dev server may override, and none in a build: an open URL override would let any visitor switch on unfinished features and skew your data. Allow it with decide({ overrides }), a function of the request context that returns true for requests that may override. Gate it on something a visitor can’t forge, such as a role in a signed session or a signed QA cookie.
Your function replaces the dev-only default, on the dev server too. To keep overrides open in dev, say so in the function, as here with Kit’s dev:
The gate runs once per flag per request, on that flag’s first read, with the context the flag was read with, so keep it cheap. On the server router, c.visitor is there too: overrides: (c) => dev || (Array.isArray(c.visitor?.roles) && c.visitor.roles.includes('qa')). Once set, overrides stays until another decide({ overrides }) replaces it; there’s no way back to the built-in default (#2310), so pass overrides: () => dev for that, or () => false to close it.
A prerendered page is rendered at build time, where no visitor’s URL exists, so overrides don’t reach it. Use the dev server or a server-rendered page to check its variants.
import { dev } from '$app/environment';
import { decide } from '@ogygia/flags';
import * as ogygia from 'ogygia/server';
import { sessions } from '$lib/server/sessions';
import '$lib/flags';
decide({
overrides: (c) =>
dev ||
(sessions
.read(c.cookies?.get('session'))
?.roles.includes('qa') ??
false)
});
export const handle = ogygia.handle();