mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
fde08d24fe
commit
a84c2d36a3
6213 files changed
+227959
-187183
No files matched your search
Vendored
+6
-7
@@ -40,10 +40,8 @@ describe('app-info disk cache', () => {
|
||||
process.env[ENV_CACHE_DIR] = dir
|
||||
})
|
||||
afterEach(async () => {
|
||||
if (prevCacheDir === undefined)
|
||||
delete process.env[ENV_CACHE_DIR]
|
||||
else
|
||||
process.env[ENV_CACHE_DIR] = prevCacheDir
|
||||
if (prevCacheDir === undefined) delete process.env[ENV_CACHE_DIR]
|
||||
else process.env[ENV_CACHE_DIR] = prevCacheDir
|
||||
await rm(dir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
@@ -91,8 +89,7 @@ describe('app-info disk cache', () => {
|
||||
await c.set('h', 'app-1', metaInfoOnly())
|
||||
const { stat } = await import('node:fs/promises')
|
||||
const s = await stat(appInfoPath(dir))
|
||||
if (platform() !== 'win32')
|
||||
expect(s.mode & 0o777).toBe(0o600)
|
||||
if (platform() !== 'win32') expect(s.mode & 0o777).toBe(0o600)
|
||||
})
|
||||
|
||||
it('missing cache file is not an error', async () => {
|
||||
@@ -112,7 +109,9 @@ describe('app-info disk cache', () => {
|
||||
await seed.set('h', 'app-2', metaInfoOnly('app-2'))
|
||||
|
||||
// Inject a corrupt sibling alongside the real one.
|
||||
const file = load(await readFile(appInfoPath(dir), 'utf8')) as { entries: Record<string, unknown> }
|
||||
const file = load(await readFile(appInfoPath(dir), 'utf8')) as {
|
||||
entries: Record<string, unknown>
|
||||
}
|
||||
file.entries['h::app-1'] = 'corrupted-string-not-object'
|
||||
await writeFile(appInfoPath(dir), dump(file), 'utf8')
|
||||
|
||||
|
||||
Vendored
+11
-10
@@ -46,7 +46,10 @@ export async function loadAppInfoCache(opts: AppInfoCacheOptions = {}): Promise<
|
||||
return {
|
||||
get: (host, appId) => state.entries.get(key(host, appId)),
|
||||
set: async (host, appId, meta) => {
|
||||
const record: AppMetaCacheRecord = { meta, fetchedAt: (opts.now ?? (() => new Date()))().toISOString() }
|
||||
const record: AppMetaCacheRecord = {
|
||||
meta,
|
||||
fetchedAt: (opts.now ?? (() => new Date()))().toISOString(),
|
||||
}
|
||||
state.entries.set(key(host, appId), record)
|
||||
await writeEntries(store, state.entries)
|
||||
},
|
||||
@@ -70,19 +73,16 @@ async function readEntries(store: Store): Promise<Map<string, AppMetaCacheRecord
|
||||
let raw: Record<string, DiskEntry>
|
||||
try {
|
||||
raw = await store.get(ENTRIES_KEY)
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
return out
|
||||
}
|
||||
// A scalar/array survives Object.entries as garbage rather than throwing.
|
||||
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
||||
return out
|
||||
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return out
|
||||
|
||||
for (const [k, e] of Object.entries(raw)) {
|
||||
try {
|
||||
out.set(k, deserialize(e))
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
// Drop unreadable entry → becomes a cache miss → consumer refetches.
|
||||
}
|
||||
}
|
||||
@@ -103,10 +103,11 @@ function deserialize(e: DiskEntry): AppMetaCacheRecord {
|
||||
}
|
||||
|
||||
function filterFields(input: unknown): AppMetaFieldKey[] {
|
||||
if (!Array.isArray(input))
|
||||
return []
|
||||
if (!Array.isArray(input)) return []
|
||||
const valid = new Set<AppMetaFieldKey>([FieldInfo, FieldParameters, FieldInputSchema])
|
||||
return input.filter((s): s is AppMetaFieldKey => typeof s === 'string' && valid.has(s as AppMetaFieldKey))
|
||||
return input.filter(
|
||||
(s): s is AppMetaFieldKey => typeof s === 'string' && valid.has(s as AppMetaFieldKey),
|
||||
)
|
||||
}
|
||||
|
||||
function serialize(record: AppMetaCacheRecord): DiskEntry {
|
||||
|
||||
Vendored
+4
-5
@@ -19,14 +19,13 @@ describe('compat-store', () => {
|
||||
process.env[ENV_CACHE_DIR] = dir
|
||||
})
|
||||
afterEach(async () => {
|
||||
if (prev === undefined)
|
||||
delete process.env[ENV_CACHE_DIR]
|
||||
else
|
||||
process.env[ENV_CACHE_DIR] = prev
|
||||
if (prev === undefined) delete process.env[ENV_CACHE_DIR]
|
||||
else process.env[ENV_CACHE_DIR] = prev
|
||||
await rm(dir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
const store = (now: Date = NOW) => loadCompatStore({ store: getCache(CACHE_COMPAT), now: () => now })
|
||||
const store = (now: Date = NOW) =>
|
||||
loadCompatStore({ store: getCache(CACHE_COMPAT), now: () => now })
|
||||
|
||||
it('is not fresh before anything is marked', async () => {
|
||||
expect((await store()).isFreshCompatible(HOST)).toBe(false)
|
||||
|
||||
Vendored
+4
-8
@@ -29,8 +29,7 @@ export async function loadCompatStore(opts: CompatStoreOptions = {}): Promise<Co
|
||||
return {
|
||||
isFreshCompatible: (host, now) => {
|
||||
const last = memory.get(host)
|
||||
if (last === undefined)
|
||||
return false
|
||||
if (last === undefined) return false
|
||||
const elapsed = Math.max(0, (now ?? clock()).getTime() - last)
|
||||
return elapsed < ttlMs
|
||||
},
|
||||
@@ -51,21 +50,18 @@ async function readCompatible(store: Store): Promise<Map<string, number>> {
|
||||
let raw: Record<string, string>
|
||||
try {
|
||||
raw = await store.get(COMPATIBLE_KEY)
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
return out
|
||||
}
|
||||
for (const [host, iso] of Object.entries(raw)) {
|
||||
const t = Date.parse(iso)
|
||||
if (!Number.isNaN(t))
|
||||
out.set(host, t)
|
||||
if (!Number.isNaN(t)) out.set(host, t)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
async function writeCompatible(store: Store, state: Map<string, number>): Promise<void> {
|
||||
const compatible: Record<string, string> = {}
|
||||
for (const [host, t] of state)
|
||||
compatible[host] = new Date(t).toISOString()
|
||||
for (const [host, t] of state) compatible[host] = new Date(t).toISOString()
|
||||
await store.set(COMPATIBLE_KEY, compatible)
|
||||
}
|
||||
Vendored
+2
-4
@@ -22,10 +22,8 @@ describe('NudgeStore', () => {
|
||||
process.env[ENV_CACHE_DIR] = dir
|
||||
})
|
||||
afterEach(async () => {
|
||||
if (prevCacheDir === undefined)
|
||||
delete process.env[ENV_CACHE_DIR]
|
||||
else
|
||||
process.env[ENV_CACHE_DIR] = prevCacheDir
|
||||
if (prevCacheDir === undefined) delete process.env[ENV_CACHE_DIR]
|
||||
else process.env[ENV_CACHE_DIR] = prevCacheDir
|
||||
await rm(dir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
|
||||
Vendored
+4
-8
@@ -28,8 +28,7 @@ export async function loadNudgeStore(opts: NudgeStoreOptions = {}): Promise<Nudg
|
||||
return {
|
||||
canWarn: (host, now) => {
|
||||
const last = memory.get(host)
|
||||
if (last === undefined)
|
||||
return true
|
||||
if (last === undefined) return true
|
||||
const elapsed = Math.max(0, (now ?? clock()).getTime() - last)
|
||||
return elapsed >= intervalMs
|
||||
},
|
||||
@@ -51,21 +50,18 @@ async function readWarned(store: Store): Promise<Map<string, number>> {
|
||||
let raw: Record<string, string>
|
||||
try {
|
||||
raw = await store.get(WARNED_KEY)
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
return out
|
||||
}
|
||||
for (const [host, iso] of Object.entries(raw)) {
|
||||
const t = Date.parse(iso)
|
||||
if (!Number.isNaN(t))
|
||||
out.set(host, t)
|
||||
if (!Number.isNaN(t)) out.set(host, t)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
async function writeWarned(store: Store, state: Map<string, number>): Promise<void> {
|
||||
const warned: Record<string, string> = {}
|
||||
for (const [host, t] of state)
|
||||
warned[host] = new Date(t).toISOString()
|
||||
for (const [host, t] of state) warned[host] = new Date(t).toISOString()
|
||||
await store.set(WARNED_KEY, warned)
|
||||
}
|
||||
Reference in new issue
Block a user