mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-19 23:06:49 +00:00
fix: base Git multi-file Compose deploy env and dossier on the effective config (#1391)
* fix: resolve the root .env at deploy and render time for Git context-dir stacks A Git multi-file source with a context dir set --project-directory to that dir, so Docker Compose looked for .env there and missed the root .env Sencho writes. Validation already passed the root .env with --env-file, so a stack could validate with one effective config but deploy or render another. Add authoredComposeEnvFileArgs, which appends --env-file <stackDir>/.env when the applied deploy spec has a context dir and a root .env exists, and wire it into the deploy/update, image-scan, render, and container-listing compose invocations so they all resolve env from the same file the validator used. A non-ENOENT access error surfaces instead of silently dropping the flag. * fix: base multi-file Git dossier and doc-drift on the effective Compose model The Stack Dossier and its documentation-drift check parsed only the stored root compose file. For a multi-file Git source, services, ports, networks, or volumes that an override file adds were invisible, so the dossier showed incomplete facts and doc-drift could falsely warn that a documented port is unpublished when an override actually publishes it. Add a secret-safe GET /stacks/:name/effective-anatomy that renders the merged effective model and extracts only structural facts (services, ports, volumes, networks, restart), never env, label, or command values. StackAnatomyPanel fetches it for multi-file Git stacks and feeds those facts into the dossier and doc-drift, falling back to the root-only parse for single-file or non-git stacks and whenever the render is unavailable. * fix: add an inline path-injection barrier to the Git env-file resolver CodeQL js/path-injection flagged the fs.access in authoredComposeEnvFileArgs because the env path derives from the route-supplied stack name and the only containment check lived in the callers, not at the sink. Resolve the stack dir against the compose base and assert containment with startsWith inline, then derive the .env path from the validated dir, mirroring the existing inline guards in renderConfig and validateCompose. Valid stack names are unaffected; a name that escapes the base now yields no --env-file. * test: stabilize the dossier doc-drift e2e against the dossier-load race The first assertion filled the access_urls field as soon as the Dossier panel was visible, but the panel's GET /stacks/:name/dossier resolves by overwriting the fields from the server (empty access_urls) and only then flips the doc-drift gate on. When the GET landed after the fill, it clobbered the typed value and the warning never rendered, so the test failed intermittently under CI timing. Wait for that GET to land before typing, mirroring the spec's openStack helper.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
vi.mock('@/lib/api', () => ({ apiFetch: vi.fn() }));
|
||||
vi.mock('./stack/StackActivityTimeline', () => ({
|
||||
@@ -338,6 +339,83 @@ describe('StackAnatomyPanel exposed footer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('StackAnatomyPanel effective dossier (multi-file Git)', () => {
|
||||
const ROOT_NO_PORTS = 'services:\n web:\n image: nginx:1.25\n';
|
||||
|
||||
function renderPanel(content = ROOT_NO_PORTS) {
|
||||
return render(
|
||||
<StackAnatomyPanel
|
||||
stackName="web"
|
||||
content={content}
|
||||
envContent=""
|
||||
selectedEnvFile=".env"
|
||||
gitSourcePending={false}
|
||||
onEditCompose={vi.fn()}
|
||||
onOpenGitSource={vi.fn()}
|
||||
onApplyUpdate={vi.fn()}
|
||||
canEdit
|
||||
applying={false}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
it('reads override-published ports from the effective model, so the dossier shows them and doc-drift does not false-warn', async () => {
|
||||
vi.mocked(apiFetch).mockImplementation(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url.includes('/update-preview')) return jsonRes(previewBody(false));
|
||||
if (url.includes('/scan-status')) return jsonRes({ status: 'ok' });
|
||||
// Multi-file source: two configured compose paths.
|
||||
if (url.includes('/git-source')) return jsonRes({
|
||||
repo_url: 'https://github.com/org/repo.git', branch: 'main',
|
||||
compose_path: 'compose.yaml', compose_paths: ['compose.yaml', 'infra/override.yaml'],
|
||||
});
|
||||
// An override publishes :9000, absent from the root file above.
|
||||
if (url.includes('/effective-anatomy')) return jsonRes({
|
||||
renderable: true, services: ['web'],
|
||||
ports: { web: [{ host: '9000', container: '9000', proto: 'tcp', published: true }] },
|
||||
volumes: {}, restart: null, networks: ['default'],
|
||||
});
|
||||
// The operator documented the override's port.
|
||||
if (url.includes('/dossier')) return jsonRes({ access_urls: 'http://192.168.1.5:9000' });
|
||||
return jsonRes(null, false);
|
||||
});
|
||||
|
||||
renderPanel();
|
||||
await userEvent.click(await screen.findByRole('tab', { name: 'Dossier' }));
|
||||
await screen.findByTestId('dossier-panel');
|
||||
|
||||
// The generated-facts ports row counts the override-published port, proving the
|
||||
// dossier read the merged effective model rather than the port-less root file.
|
||||
// (Scoped to the SPAN so it does not also match the access_urls value below.)
|
||||
await screen.findByText((content, el) => el?.tagName === 'SPAN' && content.startsWith('1 published'));
|
||||
// And doc-drift stays silent: the documented :9000 is published in the effective
|
||||
// model, so a root-only parse would false-warn here but the effective view must not.
|
||||
await waitFor(() => expect(screen.queryByTestId('dossier-doc-drift')).not.toBeInTheDocument());
|
||||
expect(vi.mocked(apiFetch).mock.calls.some(([u]) => String(u).includes('/effective-anatomy'))).toBe(true);
|
||||
});
|
||||
|
||||
it('does not fetch the effective model for a single-file Git stack', async () => {
|
||||
vi.mocked(apiFetch).mockImplementation(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url.includes('/update-preview')) return jsonRes(previewBody(false));
|
||||
if (url.includes('/scan-status')) return jsonRes({ status: 'ok' });
|
||||
if (url.includes('/git-source')) return jsonRes({
|
||||
repo_url: 'https://github.com/org/repo.git', branch: 'main',
|
||||
compose_path: 'compose.yaml', compose_paths: ['compose.yaml'],
|
||||
});
|
||||
if (url.includes('/dossier')) return jsonRes({});
|
||||
return jsonRes(null, false);
|
||||
});
|
||||
|
||||
renderPanel();
|
||||
await userEvent.click(await screen.findByRole('tab', { name: 'Dossier' }));
|
||||
await screen.findByText(/github\.com\/org\/repo#main/);
|
||||
// Give any (incorrect) effective fetch a chance to fire before asserting absence.
|
||||
await waitFor(() => expect(vi.mocked(apiFetch).mock.calls.some(([u]) => String(u).includes('/git-source'))).toBe(true));
|
||||
expect(vi.mocked(apiFetch).mock.calls.some(([u]) => String(u).includes('/effective-anatomy'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('StackAnatomyPanel capability gating (capability off)', () => {
|
||||
it('hides the Networking and Doctor tabs when the capabilities are absent', async () => {
|
||||
render(panel(false));
|
||||
|
||||
Reference in New Issue
Block a user