mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-06 08:58:05 +00:00
f23b7e1bac
* feat: ordered multi-file Compose for Git sources
Extend Git sources to deploy an ordered list of compose files merged with
docker compose -f base.yaml -f override.yaml ..., plus an optional project
directory.
- Pick and reorder compose files from the repository tree (drag to reorder on
desktop, up/down arrows on phones); manual path entry is also supported.
- The ordered set drives every stack-scoped compose command (deploy, update,
start/stop/restart/down, image scans, Compose Doctor) and the container
lookup, so a service or image declared only in an override is handled too.
- Runtime keys off the materialized set, not the saved configuration: saving a
source does not change deploy args until the pull is applied, and apply
materializes from the pending snapshot rather than live config.
- The project directory is passed as --project-directory, with -p <stack>
pinning the Compose project so container labels stay stable.
- The Mesh override is layered last; single-file sources are byte-identical to
before, and existing rows keep working via the single-path fallback.
Docs cover the picker, ordering, project directory, and the new troubleshooting
and limitations (referenced files are not materialized; the dependency graph,
drift, and networking views read the primary file).
* fix: harden multi-file Git source (hash, unlink, collisions, node id)
- hashContent folds ordered file CONTENTS (not paths) so a clean multi-file
stack is not flagged as locally edited: create/apply hash the fetched files
(repo paths) while pull hashes the on-disk files (materialized paths), which
previously disagreed and showed a false "local edits detected".
- Block unlinking a multi-file or project-directory Git source (409): the deploy
spec lives on the source row, so removing it would silently revert deploys to
root compose.yaml. Single-file sources still unlink.
- Reject materialized-path collisions in the selection validator: an additional
file equal to or nested under compose.yaml, an ancestor/descendant overlap
between selected files, and a project directory nested under a compose file
(previously a 500 at materialization).
- DockerController.getContainersByStack uses the controller's node compose dir
and passes its node id to the authored prefix, instead of the process default.
* fix: CI failures on multi-file Git source (test crash, aria query, path barrier)
- GitSourceFields no longer crashes when repoUrl/branch are falsy: the canBrowse
trim() is optional-chained, so a reusable field component tolerates partial
props. Fixes the apply-binding panel test, which feeds a minimal source object.
- GitSourcePanel tests query the footer Remove button by its exact name, so the
picker's per-file "Remove <path>" buttons no longer collide with the broad
/remove/i match (the test intent, footer Remove present/absent, is unchanged).
- validateCompose uses an inline resolve + startsWith barrier at the context-dir
mkdir sink (CodeQL does not credit the wrapped isPathWithinBase helper),
clearing the js/path-injection alert. The containment check is equivalent and
contextDir is also validated upstream.
* test: update Git source E2E spec for the multi-file compose picker
The compose-file picker replaced the single #git-source-path input and added
per-file Remove buttons, so the E2E spec drove selectors that no longer exist:
- Drop the redundant compose.yaml fills (the picker defaults to compose.yaml).
- Select the footer Remove button by exact name so the picker's per-file
"Remove <path>" buttons no longer make the locator ambiguous.
- Set a custom compose path through the picker (add via the manual input, press
Enter, then remove the default compose.yaml).
* test: match the footer Remove button with an exact Playwright name
Playwright's getByRole name option is a substring match by default, so
{ name: 'Remove' } also matched the picker's "Remove <path>" buttons. Require an
exact match so only the footer Remove button is selected.
202 lines
6.8 KiB
TypeScript
202 lines
6.8 KiB
TypeScript
import { useState, Suspense } from 'react';
|
|
import { DiffEditor } from '@/lib/monacoLoader';
|
|
import { AlertTriangle, Loader2 } from 'lucide-react';
|
|
import { Modal, ModalHeader, ModalFooter, ConfirmModal } from '@/components/ui/modal';
|
|
import { Tabs, TabsList, TabsTrigger, TabsHighlight, TabsHighlightItem } from '@/components/ui/tabs';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
import { Label } from '@/components/ui/label';
|
|
import { springs } from '@/lib/motion';
|
|
|
|
export interface PullResult {
|
|
commitSha: string;
|
|
incomingCompose: string;
|
|
incomingEnv: string | null;
|
|
currentCompose: string;
|
|
currentEnv: string | null;
|
|
validation: { ok: boolean; error?: string };
|
|
hasLocalChanges: boolean;
|
|
}
|
|
|
|
interface GitSourceDiffDialogProps {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
stackName: string;
|
|
pull: PullResult | null;
|
|
syncEnv: boolean;
|
|
autoDeployDefault: boolean;
|
|
isDarkMode: boolean;
|
|
applying: boolean;
|
|
onApply: (commitSha: string, deploy: boolean) => Promise<void>;
|
|
onDismiss: () => Promise<void>;
|
|
}
|
|
|
|
export function GitSourceDiffDialog({
|
|
open,
|
|
onOpenChange,
|
|
stackName,
|
|
pull,
|
|
syncEnv,
|
|
autoDeployDefault,
|
|
isDarkMode,
|
|
applying,
|
|
onApply,
|
|
onDismiss,
|
|
}: GitSourceDiffDialogProps) {
|
|
const [diffTab, setDiffTab] = useState<'compose' | 'env'>('compose');
|
|
const [deployAfter, setDeployAfter] = useState<boolean>(autoDeployDefault);
|
|
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
|
|
const envAvailable = syncEnv && pull?.incomingEnv !== null;
|
|
const effectiveTab = envAvailable ? diffTab : 'compose';
|
|
|
|
if (!pull) return null;
|
|
|
|
const shortSha = pull.commitSha.slice(0, 7);
|
|
|
|
const apply = async () => {
|
|
await onApply(pull.commitSha, deployAfter);
|
|
};
|
|
|
|
const handleApplyClick = () => {
|
|
if (pull.hasLocalChanges) {
|
|
setConfirmOpen(true);
|
|
return;
|
|
}
|
|
apply();
|
|
};
|
|
|
|
const currentValue = effectiveTab === 'compose' ? pull.currentCompose : (pull.currentEnv ?? '');
|
|
const incomingValue = effectiveTab === 'compose' ? pull.incomingCompose : (pull.incomingEnv ?? '');
|
|
|
|
return (
|
|
<>
|
|
<Modal size="wide" open={open} onOpenChange={onOpenChange}>
|
|
<ModalHeader
|
|
kicker="GIT · PULL PREVIEW"
|
|
title={stackName}
|
|
description={`Incoming commit ${shortSha}. Review the diff between the current on-disk stack files and the incoming Git commit.`}
|
|
/>
|
|
|
|
<div className="px-6 pt-4 space-y-3">
|
|
{!pull.validation.ok && (
|
|
<div className="flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
|
<AlertTriangle className="w-4 h-4 shrink-0 mt-0.5" strokeWidth={1.5} />
|
|
<div>
|
|
<p className="font-medium">Incoming compose failed validation</p>
|
|
<pre className="font-mono text-[11px] whitespace-pre-wrap mt-1">{pull.validation.error}</pre>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{pull.hasLocalChanges && (
|
|
<div className="flex items-start gap-2 rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning">
|
|
<AlertTriangle className="w-4 h-4 shrink-0 mt-0.5" strokeWidth={1.5} />
|
|
<div>
|
|
<p className="font-medium">Local edits detected on disk</p>
|
|
<p className="mt-0.5">Applying will overwrite changes that differ from the last applied commit.</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{envAvailable && (
|
|
<Tabs value={diffTab} onValueChange={(v) => setDiffTab(v as 'compose' | 'env')}>
|
|
<TabsList>
|
|
<TabsHighlight className="rounded-md bg-glass-highlight" transition={springs.snappy}>
|
|
<TabsHighlightItem value="compose">
|
|
<TabsTrigger value="compose">Compose</TabsTrigger>
|
|
</TabsHighlightItem>
|
|
<TabsHighlightItem value="env">
|
|
<TabsTrigger value="env">.env</TabsTrigger>
|
|
</TabsHighlightItem>
|
|
</TabsHighlight>
|
|
</TabsList>
|
|
</Tabs>
|
|
)}
|
|
</div>
|
|
|
|
<div className="px-6 pb-4 pt-3">
|
|
<div className="h-[55vh] border border-glass-border rounded-md overflow-hidden">
|
|
<Suspense fallback={<div className="w-full h-full" aria-busy="true" />}>
|
|
<DiffEditor
|
|
height="100%"
|
|
language={effectiveTab === 'compose' ? 'yaml' : 'ini'}
|
|
theme={isDarkMode ? 'vs-dark' : 'vs'}
|
|
original={currentValue}
|
|
modified={incomingValue}
|
|
options={{
|
|
readOnly: true,
|
|
renderSideBySide: true,
|
|
minimap: { enabled: false },
|
|
scrollBeyondLastLine: false,
|
|
fontFamily: "'Geist Mono', monospace",
|
|
fontSize: 12,
|
|
}}
|
|
/>
|
|
</Suspense>
|
|
</div>
|
|
</div>
|
|
|
|
<ModalFooter
|
|
hint={
|
|
<div className="flex items-center gap-2">
|
|
<Checkbox
|
|
id="git-source-deploy-after"
|
|
checked={deployAfter}
|
|
onCheckedChange={(checked) => setDeployAfter(checked === true)}
|
|
disabled={applying || !pull.validation.ok}
|
|
/>
|
|
<Label
|
|
htmlFor="git-source-deploy-after"
|
|
className="text-xs normal-case tracking-normal cursor-pointer"
|
|
>
|
|
Deploy after apply
|
|
</Label>
|
|
</div>
|
|
}
|
|
secondary={
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => onDismiss()}
|
|
disabled={applying}
|
|
>
|
|
Dismiss
|
|
</Button>
|
|
}
|
|
primary={
|
|
<Button
|
|
size="sm"
|
|
onClick={handleApplyClick}
|
|
disabled={applying || !pull.validation.ok}
|
|
>
|
|
{applying ? (
|
|
<>
|
|
<Loader2 className="w-4 h-4 mr-1.5 animate-spin" strokeWidth={1.5} />
|
|
Applying...
|
|
</>
|
|
) : (
|
|
'Apply'
|
|
)}
|
|
</Button>
|
|
}
|
|
/>
|
|
</Modal>
|
|
|
|
<ConfirmModal
|
|
open={confirmOpen}
|
|
onOpenChange={setConfirmOpen}
|
|
variant="destructive"
|
|
kicker="GIT · LOCAL CHANGES"
|
|
title="Overwrite local edits?"
|
|
description="The on-disk stack files differ from the last applied commit. Applying this pull will replace them with the incoming content."
|
|
confirmLabel="Overwrite and apply"
|
|
confirming={applying}
|
|
onConfirm={async () => {
|
|
setConfirmOpen(false);
|
|
await apply();
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|