mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 06:21:12 +00:00
refactor(setup): share registration inspection preflight (#15477)
This commit is contained in:
1 parent
5d004504f3
commit
0f372680a3
1 file changed
+50
-99
@@ -1030,62 +1030,61 @@ const inspectClientDocument = async (
|
||||
remediation:
|
||||
"The configuration path is unsafe or unresolved. Check ownership and symbolic links before rerunning setup.",
|
||||
};
|
||||
const inspectRegistration = async (
|
||||
parsed?: ClientConfigurationDocument,
|
||||
original?: string,
|
||||
): Promise<Result<unknown, string>> => {
|
||||
const ownershipBlocker = writeTargetOwnershipBlocker(
|
||||
client,
|
||||
files.value,
|
||||
parsed,
|
||||
original,
|
||||
platform,
|
||||
);
|
||||
if (ownershipBlocker !== undefined) return err(ownershipBlocker);
|
||||
const desired = await clientConfigurationDesired(
|
||||
client,
|
||||
providerEnvironment,
|
||||
command,
|
||||
parsed,
|
||||
files.value,
|
||||
platform,
|
||||
launcherEnvironment,
|
||||
resolveProviderRequestBudget,
|
||||
);
|
||||
if (!desired.ok) return err(configurationRemediation(desired.error));
|
||||
const override = inlineOverrideBlocker(
|
||||
client,
|
||||
files.value,
|
||||
desired.value,
|
||||
platform,
|
||||
parsed,
|
||||
);
|
||||
if (override !== undefined) return err(override);
|
||||
const policy = await readClientPolicyBlock(
|
||||
client,
|
||||
parsed,
|
||||
desired.value,
|
||||
undefined,
|
||||
launcherEnvironment,
|
||||
platform,
|
||||
);
|
||||
if (!policy.ok) {
|
||||
throwCleanupFailure(policy.error);
|
||||
return err(policy.error.detail);
|
||||
}
|
||||
return policy.value === undefined ? desired : err(policy.value);
|
||||
};
|
||||
let original: string;
|
||||
try {
|
||||
original = await readRegularFileText(transactionPath);
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof RegularFileCleanupFailure) throw cause;
|
||||
if (isEnoentError(cause)) {
|
||||
const ownershipBlocker = writeTargetOwnershipBlocker(
|
||||
client,
|
||||
files.value,
|
||||
undefined,
|
||||
undefined,
|
||||
platform,
|
||||
);
|
||||
if (ownershipBlocker !== undefined)
|
||||
return { status: "invalid", remediation: ownershipBlocker };
|
||||
const desired = await clientConfigurationDesired(
|
||||
client,
|
||||
providerEnvironment,
|
||||
command,
|
||||
undefined,
|
||||
files.value,
|
||||
platform,
|
||||
launcherEnvironment,
|
||||
resolveProviderRequestBudget,
|
||||
);
|
||||
if (!desired.ok)
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation: configurationRemediation(desired.error),
|
||||
};
|
||||
const override = inlineOverrideBlocker(
|
||||
client,
|
||||
files.value,
|
||||
desired.value,
|
||||
platform,
|
||||
);
|
||||
if (override !== undefined)
|
||||
return { status: "invalid", remediation: override };
|
||||
// This read establishes absence; do not reuse an earlier user-file policy.
|
||||
const policy = await readClientPolicyBlock(
|
||||
client,
|
||||
undefined,
|
||||
desired.value,
|
||||
undefined,
|
||||
launcherEnvironment,
|
||||
platform,
|
||||
);
|
||||
if (!policy.ok) {
|
||||
throwCleanupFailure(policy.error);
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation: policy.error.detail,
|
||||
};
|
||||
}
|
||||
if (policy.value !== undefined)
|
||||
return { status: "invalid", remediation: policy.value };
|
||||
const preflight = await inspectRegistration();
|
||||
if (!preflight.ok)
|
||||
return { status: "invalid", remediation: preflight.error };
|
||||
const fallback = await readZcodeFallbackServers(client, platform);
|
||||
if (!fallback.ok) {
|
||||
if (fallback.error.kind !== "registration_ownership")
|
||||
@@ -1119,56 +1118,8 @@ const inspectClientDocument = async (
|
||||
remediation: configurationRemediation(writeDocument.error),
|
||||
};
|
||||
const parsed = writeDocument.value;
|
||||
const ownershipBlocker = writeTargetOwnershipBlocker(
|
||||
client,
|
||||
files.value,
|
||||
parsed,
|
||||
original,
|
||||
platform,
|
||||
);
|
||||
if (ownershipBlocker !== undefined)
|
||||
return { status: "invalid", remediation: ownershipBlocker };
|
||||
const desired = await clientConfigurationDesired(
|
||||
client,
|
||||
providerEnvironment,
|
||||
command,
|
||||
parsed,
|
||||
files.value,
|
||||
platform,
|
||||
launcherEnvironment,
|
||||
resolveProviderRequestBudget,
|
||||
);
|
||||
if (!desired.ok)
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation: configurationRemediation(desired.error),
|
||||
};
|
||||
const override = inlineOverrideBlocker(
|
||||
client,
|
||||
files.value,
|
||||
desired.value,
|
||||
platform,
|
||||
parsed,
|
||||
);
|
||||
if (override !== undefined)
|
||||
return { status: "invalid", remediation: override };
|
||||
const policy = await readClientPolicyBlock(
|
||||
client,
|
||||
parsed,
|
||||
desired.value,
|
||||
undefined,
|
||||
launcherEnvironment,
|
||||
platform,
|
||||
);
|
||||
if (!policy.ok) {
|
||||
throwCleanupFailure(policy.error);
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation: policy.error.detail,
|
||||
};
|
||||
}
|
||||
if (policy.value !== undefined)
|
||||
return { status: "invalid", remediation: policy.value };
|
||||
const desired = await inspectRegistration(parsed, original);
|
||||
if (!desired.ok) return { status: "invalid", remediation: desired.error };
|
||||
if (
|
||||
registrationCurrent(parsed, desired.value) &&
|
||||
(await privateProfileCurrent(client, original))
|
||||
|
||||
Reference in new issue
Block a user