feat: extend Telegram dock commands and config hashing (#929)
Thanks @grp06. Co-authored-by: George Pickett <gpickett00@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
loadConfig,
|
||||
parseConfigJson5,
|
||||
readConfigFileSnapshot,
|
||||
resolveConfigSnapshotHash,
|
||||
validateConfigObject,
|
||||
writeConfigFile,
|
||||
} from "../config/config.js";
|
||||
@@ -33,7 +34,8 @@ function requireConfigBaseHash(
|
||||
snapshot: Awaited<ReturnType<typeof readConfigFileSnapshot>>,
|
||||
): { ok: true } | { ok: false; error: { code: string; message: string } } {
|
||||
if (!snapshot.exists) return { ok: true };
|
||||
if (typeof snapshot.raw !== "string" || !snapshot.hash) {
|
||||
const snapshotHash = resolveConfigSnapshotHash(snapshot);
|
||||
if (!snapshotHash) {
|
||||
return {
|
||||
ok: false,
|
||||
error: {
|
||||
@@ -52,7 +54,7 @@ function requireConfigBaseHash(
|
||||
},
|
||||
};
|
||||
}
|
||||
if (baseHash !== snapshot.hash) {
|
||||
if (baseHash !== snapshotHash) {
|
||||
return {
|
||||
ok: false,
|
||||
error: {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
loadConfig,
|
||||
parseConfigJson5,
|
||||
readConfigFileSnapshot,
|
||||
resolveConfigSnapshotHash,
|
||||
validateConfigObject,
|
||||
writeConfigFile,
|
||||
} from "../../config/config.js";
|
||||
@@ -42,7 +43,8 @@ function requireConfigBaseHash(
|
||||
respond: RespondFn,
|
||||
): boolean {
|
||||
if (!snapshot.exists) return true;
|
||||
if (typeof snapshot.raw !== "string" || !snapshot.hash) {
|
||||
const snapshotHash = resolveConfigSnapshotHash(snapshot);
|
||||
if (!snapshotHash) {
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
@@ -65,7 +67,7 @@ function requireConfigBaseHash(
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (baseHash !== snapshot.hash) {
|
||||
if (baseHash !== snapshotHash) {
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveConfigSnapshotHash } from "../config/config.js";
|
||||
|
||||
import {
|
||||
connectOk,
|
||||
installGatewayTestHooks,
|
||||
@@ -43,12 +45,15 @@ describe("gateway config.patch", () => {
|
||||
params: {},
|
||||
}),
|
||||
);
|
||||
const getRes = await onceMessage<{ ok: boolean; payload?: { hash?: string } }>(
|
||||
const getRes = await onceMessage<{ ok: boolean; payload?: { hash?: string; raw?: string } }>(
|
||||
ws,
|
||||
(o) => o.type === "res" && o.id === getId,
|
||||
);
|
||||
expect(getRes.ok).toBe(true);
|
||||
const baseHash = getRes.payload?.hash;
|
||||
const baseHash = resolveConfigSnapshotHash({
|
||||
hash: getRes.payload?.hash,
|
||||
raw: getRes.payload?.raw,
|
||||
});
|
||||
expect(typeof baseHash).toBe("string");
|
||||
|
||||
const patchId = "req-patch";
|
||||
|
||||
Reference in New Issue
Block a user