frontend-app-api: make session state opaque

Replace exposed prepared app APIs and predicate plumbing with a reusable opaque session state so apps can skip sign-in without leaking internals. Align the specialized app flow around getSignIn().ready and finalize(sessionState) for explicit session bootstrap and reuse.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-12 18:14:14 +01:00
parent b14e301bb6
commit 94e91d9de3
3 changed files with 8 additions and 112 deletions
@@ -1731,107 +1731,6 @@ describe('createSpecializedApp', () => {
);
});
it('should reuse predicate context gathered during sign-in completion', async () => {
const identityApi = {
getProfileInfo: async () => ({ displayName: 'Test User' }),
getBackstageIdentity: async () => ({
type: 'user' as const,
userEntityRef: 'user:default/test-user',
ownershipEntityRefs: ['user:default/test-user'],
}),
getCredentials: async () => ({ token: 'token' }),
signOut: async () => {},
};
const featureFlagsApi = {
isActive: jest.fn((name: string) => name === 'test-flag'),
registerFlag: jest.fn(),
getRegisteredFlags: () => [],
save: jest.fn(),
} as unknown as typeof featureFlagsApiRef.T;
const gatedAppPlugin = appPluginOriginal.withOverrides({
extensions: [
appPluginOriginal.getExtension('app/layout').override({
if: { featureFlags: { $contains: 'test-flag' } },
factory: () => [
coreExtensionData.reactElement(<div>Flagged Layout</div>),
],
}),
],
});
const preparedApp = prepareSpecializedApp({
features: [
gatedAppPlugin,
createFrontendModule({
pluginId: 'app',
extensions: [
ApiBlueprint.make({
params: defineParams =>
defineParams({
api: featureFlagsApiRef,
deps: {},
factory: () => featureFlagsApi,
}),
}),
gatedAppPlugin.getExtension('sign-in-page:app').override({
factory: () => {
function SignInPage(props: {
onSignInSuccess(identity: IdentityApi): void;
}) {
useEffect(() => {
props.onSignInSuccess(identityApi);
}, [props]);
return <div>Custom Sign In</div>;
}
return [signInPageComponentDataRef(SignInPage)];
},
}),
],
}),
],
});
const signIn = preparedApp.getSignIn();
render(signIn!.element);
await expect(
screen.findByText('Custom Sign In'),
).resolves.toBeInTheDocument();
await signIn!.complete;
expect(featureFlagsApi.isActive).toHaveBeenCalledWith('test-flag');
expect(featureFlagsApi.isActive).toHaveBeenCalledTimes(1);
const finalizedApp = preparedApp.finalize();
render(
finalizedApp.tree.root.instance!.getData(
coreExtensionData.reactElement,
),
);
expect(screen.getByText('Flagged Layout')).toBeInTheDocument();
});
it('should reject bootstrap-visible extensions that use if predicates', () => {
expect(() =>
prepareSpecializedApp({
features: [
appPluginOriginal,
createFrontendModule({
pluginId: 'app',
extensions: [
appPluginOriginal.getExtension('sign-in-page:app').override({
if: { featureFlags: { $contains: 'test-flag' } },
}),
],
}),
],
}),
).toThrow(
"Extension 'sign-in-page:app' uses 'if' before the session boundary at 'app/root.children'. Move it behind the session boundary or remove the predicate.",
);
});
it('should gate finalize behind internal async sign-in finalization', async () => {
const identityApi = {
getProfileInfo: async () => ({ displayName: 'Test User' }),