mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 14:36:35 +09:00
fix(windows): use native storage paths
This commit is contained in:
1 parent
03e381eaa2
commit
53d92a5179
3 files changed
+60
-4
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import { execFileSync } from 'child_process';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname } from 'node:path';
|
||||
import { afterEach, expect, it, vi } from 'vitest';
|
||||
import { RvfaPublisher } from '../src/appliance/rvfa-distribution.js';
|
||||
import { downloadFromGCS, uploadToGCS } from '../src/transfer/storage/gcs.js';
|
||||
|
||||
vi.mock('child_process', () => ({ execFileSync: vi.fn() }));
|
||||
vi.mock('fs', () => ({
|
||||
readFileSync: vi.fn(() => Buffer.from('fixture')),
|
||||
unlinkSync: vi.fn(),
|
||||
writeFileSync: vi.fn(),
|
||||
}));
|
||||
vi.mock('node:fs/promises', () => ({ readFile: vi.fn() }));
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.restoreAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
const bucket = 'fixture-bucket';
|
||||
const uri = 'gs://fixture-bucket/example.json';
|
||||
|
||||
it('places GCS upload staging files in the OS temporary directory', async () => {
|
||||
vi.stubEnv('TMPDIR', undefined);
|
||||
await uploadToGCS(Buffer.from('fixture'), { name: 'example.json', config: { bucket } });
|
||||
const [command, args] = vi.mocked(execFileSync).mock.calls[0];
|
||||
expect(command).toBe('gcloud');
|
||||
expect(dirname((args as string[])[2])).toBe(tmpdir());
|
||||
});
|
||||
|
||||
it('places GCS download staging files in the OS temporary directory', async () => {
|
||||
vi.stubEnv('TMPDIR', undefined);
|
||||
await expect(downloadFromGCS(uri, { bucket })).resolves.toEqual(Buffer.from('fixture'));
|
||||
const [command, args] = vi.mocked(execFileSync).mock.calls[0];
|
||||
expect(command).toBe('gcloud');
|
||||
expect(dirname((args as string[])[3])).toBe(tmpdir());
|
||||
});
|
||||
|
||||
it.runIf(process.platform === 'win32')('publishes a Windows appliance path using only its filename', async () => {
|
||||
const file = String.raw`C:\fixtures\example.rvf`;
|
||||
const data = Buffer.from('fixture');
|
||||
vi.mocked(readFile).mockResolvedValue(data);
|
||||
const publisher = new RvfaPublisher({ pinataJwt: 'fixture-token' });
|
||||
const upload = vi.spyOn(publisher as unknown as {
|
||||
upload: (name: string, bytes: Buffer, metadata: Record<string, string>) => Promise<unknown>;
|
||||
}, 'upload').mockResolvedValue({});
|
||||
|
||||
await publisher.publish(file);
|
||||
|
||||
expect(readFile).toHaveBeenCalledWith(file);
|
||||
expect(upload).toHaveBeenCalledWith('example.rvf', data, expect.any(Object));
|
||||
});
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import { createHash, sign, verify as edVerify } from 'node:crypto';
|
||||
import { readFile, writeFile, rename, unlink, copyFile, mkdir } from 'node:fs/promises';
|
||||
import { dirname } from 'node:path';
|
||||
import { basename, dirname } from 'node:path';
|
||||
import { request as httpsRequest } from 'node:https';
|
||||
import { gzipSync, gunzipSync } from 'node:zlib';
|
||||
import { RvfaReader, RvfaWriter } from './rvfa-format.js';
|
||||
@@ -351,7 +351,7 @@ export class RvfaPublisher {
|
||||
|
||||
async publish(rvfaPath: string, meta?: PublishMetadata): Promise<PublishResult> {
|
||||
const data = await readFile(rvfaPath);
|
||||
const name = meta?.name || rvfaPath.split('/').pop() || 'appliance.rvf';
|
||||
const name = meta?.name || basename(rvfaPath) || 'appliance.rvf';
|
||||
return this.upload(name, data, {
|
||||
type: 'rvfa-appliance', version: meta?.version || '',
|
||||
profile: meta?.profile || '', description: meta?.description || '',
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
import * as crypto from 'crypto';
|
||||
import * as fs from 'fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import * as path from 'path';
|
||||
import { execFileSync } from 'child_process';
|
||||
|
||||
@@ -136,7 +137,7 @@ export async function uploadToGCS(
|
||||
console.log(`[GCS] Uploading to gs://${config.bucket}/${objectPath}...`);
|
||||
|
||||
// Write content to temp file
|
||||
const tempDir = process.env.TMPDIR || '/tmp';
|
||||
const tempDir = tmpdir();
|
||||
const tempFile = path.join(tempDir, `claude-flow-upload-${Date.now()}.json`);
|
||||
fs.writeFileSync(tempFile, content);
|
||||
|
||||
@@ -204,7 +205,7 @@ export async function downloadFromGCS(
|
||||
console.log(`[GCS] Downloading from ${uri}...`);
|
||||
|
||||
// Write to temp file first
|
||||
const tempDir = process.env.TMPDIR || '/tmp';
|
||||
const tempDir = tmpdir();
|
||||
const tempFile = path.join(tempDir, `claude-flow-download-${Date.now()}.json`);
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user