mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-09-01 13:18:08 +00:00
feat(git): classify managed-file changes before apply (#1832)
* feat(git): classify managed-file changes before apply Pull now builds a fingerprint-bound plan of adds, modifies, deletes, and local conflicts. Apply refuses stale or blocked plans instead of overwriting live files, and promotion stays the only filesystem mutator. * fix(git): contain stack-dir probes before filesystem access The missing-stack and root-.env existence checks now resolve against the compose base and refuse paths that escape it before lstat or existsSync. * fix(git): address managed-file change plan audit blockers Wire build-context live inventory into the planner, reject special file nodes without readFile, fingerprint configured project env files, enrich plan metadata, and compute the create plan before promotion. Redact drift ledger service keys for managed-path conflicts and clear pending plan columns on revision reset. * fix(git): unblock change-plan CI sinks and fifo test Hash stack files through a contained open plus fstat on the same handle so CodeQL no longer flags the lstat/read race, and create fifo fixtures with mkfifo instead of mkfifoSync. * fix(git): preserve unowned context files and align candidate validation Inspect prior and candidate build contexts together, delete only owned paths, reject context-root symlinks before walking, and validate with the env-file model deploy will use after promotion. * fix(git): contain live context and candidate env path sinks Inline resolve and startsWith at the lstat and access calls so containment is checked at the filesystem sink. * fix(git): resolve live context walks from the compose root Rebuild readdir, lstat, and access paths from the compose directory at each sink so containment is checked against a known-safe base. * fix(git): validate synced env removal against post-promotion files A managed .env that the next revision omits must not be used for candidate validation or invocation, because promotion deletes it. Context walks now bound directory entries and skip descendants under nested symlinks. Plan fingerprints bind review metadata and secret-path matching covers .env.* names. * docs(git): capture classified change-plan review screenshots Replace the old Monaco pull-preview images with the classified operation list used by Apply. * fix(git): treat invocation drift as reviewable, not a file conflict A live Compose command-line change is not a managed-file conflict. Reviewed apply records the incoming invocation; webhook auto-apply still refuses.
This commit is contained in:
@@ -32,8 +32,28 @@ vi.mock('@/context/NodeContext', () => ({
|
||||
// Drive applyPull(commitSha, deploy=true) directly without standing up the real
|
||||
// diff UI; the panel passes applyPull as onApply.
|
||||
vi.mock('./GitSourceDiffDialog', () => ({
|
||||
GitSourceDiffDialog: ({ onApply }: { onApply: (sha: string, deploy: boolean) => void }) => (
|
||||
<button data-testid="apply-deploy" onClick={() => onApply('sha-123', true)}>apply</button>
|
||||
GitSourceDiffDialog: ({
|
||||
onApply,
|
||||
pull,
|
||||
}: {
|
||||
onApply: (sha: string, deploy: boolean, fp: string) => void;
|
||||
pull: PullResult | null;
|
||||
}) => (
|
||||
<div>
|
||||
<span data-testid="plan-fingerprint">{pull?.planFingerprint ?? ''}</span>
|
||||
<button
|
||||
data-testid="apply-deploy"
|
||||
onClick={() => onApply('sha-123', true, pull?.planFingerprint ?? 'fp-test')}
|
||||
>
|
||||
apply deploy
|
||||
</button>
|
||||
<button
|
||||
data-testid="apply-only"
|
||||
onClick={() => onApply('sha-123', false, pull?.planFingerprint ?? 'fp-test')}
|
||||
>
|
||||
apply
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
vi.mock('@/components/ui/toast-store', () => ({
|
||||
@@ -48,6 +68,8 @@ vi.mock('@/components/ui/toast-store', () => ({
|
||||
|
||||
import { apiFetch } from '@/lib/api';
|
||||
import { GitSourcePanel } from './GitSourcePanel';
|
||||
import { toast } from '@/components/ui/toast-store';
|
||||
import type { PullResult } from './GitSourceDiffDialog';
|
||||
|
||||
function jsonRes(body: unknown, ok = true, status = 200) {
|
||||
return { ok, status, json: async () => body, text: async () => '' } as unknown as Response;
|
||||
@@ -90,6 +112,9 @@ beforeEach(() => {
|
||||
vi.mocked(apiFetch).mockReset();
|
||||
nodeCtl.activeNode = null;
|
||||
dfCtl.params = null;
|
||||
vi.mocked(toast.success).mockClear();
|
||||
vi.mocked(toast.warning).mockClear();
|
||||
vi.mocked(toast.error).mockClear();
|
||||
});
|
||||
|
||||
describe('GitSourcePanel load', () => {
|
||||
@@ -129,17 +154,87 @@ describe('GitSourcePanel deploy-mode apply node binding', () => {
|
||||
});
|
||||
|
||||
it('binds both runWithLog and the apply POST to the captured node when deploying', async () => {
|
||||
vi.mocked(apiFetch).mockImplementation(async (url: string) => {
|
||||
if (String(url).includes('/git-source/apply')) {
|
||||
return jsonRes({ applied: true, deployed: true });
|
||||
}
|
||||
return jsonRes(LINKED_SOURCE);
|
||||
});
|
||||
render(panel());
|
||||
fireEvent.click(await screen.findByTestId('apply-deploy'));
|
||||
|
||||
await waitFor(() => {
|
||||
const applyCall = vi.mocked(apiFetch).mock.calls.find(c => String(c[0]).includes('/git-source/apply'));
|
||||
expect(applyCall?.[1]).toEqual(expect.objectContaining({ nodeId: 4 }));
|
||||
expect(JSON.parse(String((applyCall?.[1] as { body?: string })?.body))).toEqual({
|
||||
commitSha: 'sha-123',
|
||||
planFingerprint: 'fp-test',
|
||||
deploy: true,
|
||||
});
|
||||
});
|
||||
expect(dfCtl.params).toEqual(expect.objectContaining({ action: 'deploy', nodeId: 4 }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('GitSourcePanel stale plan handling', () => {
|
||||
const PULL_RESULT: PullResult = {
|
||||
commitSha: 'sha-old',
|
||||
validation: { ok: true },
|
||||
refusals: [],
|
||||
warnings: [],
|
||||
plan: {
|
||||
blocked: false,
|
||||
counts: {
|
||||
add: 0,
|
||||
modify: 0,
|
||||
delete: 0,
|
||||
rename: 0,
|
||||
unchanged: 1,
|
||||
localModified: 0,
|
||||
localMissing: 0,
|
||||
typeChanged: 0,
|
||||
unmanagedCollision: 0,
|
||||
invocation: 0,
|
||||
},
|
||||
operations: [],
|
||||
invocation: { candidateChanged: false, liveDiverged: false },
|
||||
},
|
||||
planFingerprint: 'fp-old',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(apiFetch).mockImplementation(async (url: string) => {
|
||||
if (String(url).includes('/git-source/pull')) {
|
||||
return jsonRes(PULL_RESULT);
|
||||
}
|
||||
if (String(url).includes('/git-source/apply')) {
|
||||
return jsonRes({
|
||||
error: 'The change plan is stale.',
|
||||
code: 'STALE_PLAN',
|
||||
planFingerprint: 'fp-new',
|
||||
plan: { ...PULL_RESULT.plan, blocked: true },
|
||||
}, false, 409);
|
||||
}
|
||||
return jsonRes(LINKED_SOURCE);
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the diff open and replaces the pending plan on STALE_PLAN', async () => {
|
||||
render(panel());
|
||||
fireEvent.click(await screen.findByRole('button', { name: /pull now/i }));
|
||||
await screen.findByTestId('plan-fingerprint');
|
||||
expect(screen.getByTestId('plan-fingerprint')).toHaveTextContent('fp-old');
|
||||
|
||||
fireEvent.click(screen.getByTestId('apply-only'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(toast.warning).toHaveBeenCalledWith(expect.stringMatching(/stale/i));
|
||||
expect(screen.getByTestId('plan-fingerprint')).toHaveTextContent('fp-new');
|
||||
});
|
||||
expect(toast.success).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GitSourcePanel manifest summary', () => {
|
||||
it('renders the managed-project section when the source carries a manifest', async () => {
|
||||
const summary = {
|
||||
|
||||
Reference in New Issue
Block a user