gpt-image-playground deploy commited on
Commit
76bde47
·
1 Parent(s): e344055

Deploy 36a4274 to Docker Space

Browse files
README.md CHANGED
@@ -12,7 +12,7 @@ app_port: 4783
12
  本地 AI 图片创作工作台,面向中文内容运营、设计草图和自动化生图流程。支持 `gpt-image-2`、OpenAI 兼容图片接口、文生图、图生图、遮罩编辑、批量任务、历史复用、费用追踪和 Agent API。
13
 
14
  <p align="center">
15
- <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/444b7abc99f5bfa03760ceefb2beb0d790f0aba9/readme-images/interface.jpg?v=20260608-07b596b" alt="GPT Image Playground 界面" width="900"/>
16
  </p>
17
 
18
  ## 快速开始
@@ -78,13 +78,13 @@ start-windows.bat
78
  遮罩编辑示例:
79
 
80
  <p align="center">
81
- <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/444b7abc99f5bfa03760ceefb2beb0d790f0aba9/readme-images/mask-creation.jpg?v=20260608-07b596b" alt="遮罩创建" width="900"/>
82
  </p>
83
 
84
  历史与费用示例:
85
 
86
  <p align="center">
87
- <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/444b7abc99f5bfa03760ceefb2beb0d790f0aba9/readme-images/history.jpg?v=20260608-07b596b" alt="历史面板" width="900"/>
88
  </p>
89
 
90
  ## 配置
 
12
  本地 AI 图片创作工作台,面向中文内容运营、设计草图和自动化生图流程。支持 `gpt-image-2`、OpenAI 兼容图片接口、文生图、图生图、遮罩编辑、批量任务、历史复用、费用追踪和 Agent API。
13
 
14
  <p align="center">
15
+ <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/36a4274a16b48a50059a1a47e8711352c09c479a/readme-images/interface.jpg?v=20260608-07b596b" alt="GPT Image Playground 界面" width="900"/>
16
  </p>
17
 
18
  ## 快速开始
 
78
  遮罩编辑示例:
79
 
80
  <p align="center">
81
+ <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/36a4274a16b48a50059a1a47e8711352c09c479a/readme-images/mask-creation.jpg?v=20260608-07b596b" alt="遮罩创建" width="900"/>
82
  </p>
83
 
84
  历史与费用示例:
85
 
86
  <p align="center">
87
+ <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/36a4274a16b48a50059a1a47e8711352c09c479a/readme-images/history.jpg?v=20260608-07b596b" alt="历史面板" width="900"/>
88
  </p>
89
 
90
  ## 配置
docs/deployment/huggingface-space-free.md CHANGED
@@ -1,6 +1,6 @@
1
  # Hugging Face Space 部署
2
 
3
- 本文档描述如何把本项目部署到 Hugging Face Docker Space,用作公网图片生成服务。Docker Space 的创建和更新权限取决于 Hugging Face 的当前账户政策;当前账户若`hf upload` 阶段收到 Docker Space 创建接口的 `402`,部署脚本对已存在且可认证写入的固定 Space 回退到 Git 推送,不绕过新建 Docker Space 的账户限制。
4
 
5
  ## 目标形态
6
 
@@ -81,7 +81,7 @@ npm run agent:doctor
81
  - `doctor`:统一诊断入口,默认包含 HF Space 只读远端检查。
82
  - `verify`:提交前基线,执行测试、lint、脚本语法、构建和 `git diff --check`;需要真实 PostgreSQL gate 时加 `--postgres`。
83
  - `deploy:local`:重建本地 Docker 服务并探测真实 HTTP 端点;加 `--memory` 会断言 memory/indexeddb overlay 生效。
84
- - `deploy:space`:上传当前干净 git HEAD 到固定 HF Space,并做只读公网验证;已存在 Docker Space 遇到已知创建政策 `402` 时,会使用认证 Git 推送回退
85
  - `agent:doctor`:通过仓库 Skill 脚本执行只读 Agent API 契约检查,不触发真实生图。
86
 
87
  HF Space 交互使用官方 `hf` CLI。不要维护本机 access 文件,不要把 `APP_PASSWORD`、`AGENT_API_TOKEN`、OpenAI Key 或 Hugging Face token 写入仓库文件。
@@ -97,8 +97,8 @@ npm run deploy:space
97
  - 使用 `git status --porcelain` 拒绝脏工作区。
98
  - 使用 `git archive HEAD` 生成临时源码目录,只上传已跟踪源码。
99
  - Space 发布包会排除根目录 `readme-images/` 中的 README 文档截图,以兼容 Hugging Face Git 的二进制文件门禁;Space README 会改用对应 GitHub 提交的不可变图片地址。
100
- - 优先使用 `hf upload` 上传到 `misonL/gpt-image-playground-customer`
101
- - 仅当 `hf upload`既有 Docker Space 创建政策 `402` 失败,克隆该固定 Space、同步已跟踪源码并使用认证 Git 推送其他错误不会自动回退。
102
  - 等待新 Space commit 进入 `RUNNING`。
103
  - 检查 `/api/auth-status`、`/api/agent/capabilities` 和 `/api/runtime-capabilities`,不触发真实生图。
104
 
 
1
  # Hugging Face Space 部署
2
 
3
+ 本文档描述如何把本项目部署到 Hugging Face Docker Space,用作公网图片生成服务。Docker Space 的创建和更新权限取决于 Hugging Face 的当前账户政策;固定目标已存且元数据标识为 Docker,部署脚本会直接使用认证 Git 推送,避免 `hf upload` 触发创建接口的已知 `402`。这不绕过新建 Docker Space 的账户限制。
4
 
5
  ## 目标形态
6
 
 
81
  - `doctor`:统一诊断入口,默认包含 HF Space 只读远端检查。
82
  - `verify`:提交前基线,执行测试、lint、脚本语法、构建和 `git diff --check`;需要真实 PostgreSQL gate 时加 `--postgres`。
83
  - `deploy:local`:重建本地 Docker 服务并探测真实 HTTP 端点;加 `--memory` 会断言 memory/indexeddb overlay 生效。
84
+ - `deploy:space`:上传当前干净 git HEAD 到固定 HF Space,并做只读公网验证;已存在 Docker Space 根据远端元数据直接使用认证 Git 推送,其他类型才优先尝试 `hf upload`
85
  - `agent:doctor`:通过仓库 Skill 脚本执行只读 Agent API 契约检查,不触发真实生图。
86
 
87
  HF Space 交互使用官方 `hf` CLI。不要维护本机 access 文件,不要把 `APP_PASSWORD`、`AGENT_API_TOKEN`、OpenAI Key 或 Hugging Face token 写入仓库文件。
 
97
  - 使用 `git status --porcelain` 拒绝脏工作区。
98
  - 使用 `git archive HEAD` 生成临时源码目录,只上传已跟踪源码。
99
  - Space 发布包会排除根目录 `readme-images/` 中的 README 文档截图,以兼容 Hugging Face Git 的二进制文件门禁;Space README 会改用对应 GitHub 提交的不可变图片地址。
100
+ - 读取远端 Space 元数据;当前固定 Docker Space 直接克隆、同步已跟踪源码并使用认证 Git 推送
101
+ - Docker Space 才优先使用 `hf upload`;仅当它命中既有 Docker Space 创建政策 `402` 时才回退到认证 Git 推送其他错误不会自动回退。
102
  - 等待新 Space commit 进入 `RUNNING`。
103
  - 检查 `/api/auth-status`、`/api/agent/capabilities` 和 `/api/runtime-capabilities`,不触发真实生图。
104
 
public/hf-space-deploy-marker.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "schema_version": 1,
3
- "local_sha": "444b7abc99f5bfa03760ceefb2beb0d790f0aba9",
4
- "created_at": "2026-07-20T08:14:53.507Z",
5
- "deploy_id": "a25ce1ac-a4d0-4982-bc6d-796a92ff195f"
6
  }
 
1
  {
2
  "schema_version": 1,
3
+ "local_sha": "36a4274a16b48a50059a1a47e8711352c09c479a",
4
+ "created_at": "2026-07-20T08:55:43.290Z",
5
+ "deploy_id": "f19889c7-48c8-4069-8dd0-cae4ae827d8f"
6
  }
scripts/deploy-hf-space.mjs CHANGED
@@ -1,5 +1,6 @@
1
  #!/usr/bin/env node
2
-
 
3
  import { spawnSync } from 'node:child_process';
4
  import { randomUUID } from 'node:crypto';
5
  import { cpSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
@@ -7,9 +8,6 @@ import { tmpdir } from 'node:os';
7
  import { join } from 'node:path';
8
  import { setTimeout as delay } from 'node:timers/promises';
9
 
10
- import { fetchJsonWithTimeout, parseJsonPayload, runCommandStrict } from './command-center-utils.mjs';
11
- import { assertKnownOptions, HF_SPACE_ID, HF_SPACE_URL, isMainModule } from './hf-space-doctor-utils.mjs';
12
-
13
  const STATUS_POLL_ATTEMPTS = 40;
14
  const STATUS_POLL_INTERVAL_MS = 10_000;
15
  const PUBLIC_ENDPOINT_TIMEOUT_MS = 10_000;
@@ -34,10 +32,11 @@ function printHelp() {
34
  console.log(`Usage:
35
  npm run deploy:hf-space
36
 
37
- Deploys the current clean git HEAD to ${HF_SPACE_ID} with the official hf CLI.
38
 
39
- The script uploads a temporary git archive, waits for the Space to run the new
40
- Space commit, and performs read-only public endpoint checks.`);
 
41
  }
42
 
43
  function runText(command, args, options = {}) {
@@ -93,7 +92,9 @@ export function isSpaceDeployPath(filePath) {
93
  const normalized = String(filePath || '')
94
  .replaceAll('\\', '/')
95
  .replace(/^\.\//, '');
96
- return normalized.length > 0 && !SPACE_DEPLOY_EXCLUDED_PATH_PREFIXES.some((prefix) => normalized.startsWith(prefix));
 
 
97
  }
98
 
99
  export function rewriteSpaceReadmeImageSources(readme, repoSlug, localSha) {
@@ -112,7 +113,11 @@ function prepareSourceTree(repoSlug, localSha) {
112
  runText('tar', ['-x', '-C', sourceDir], { input: archive });
113
  rmSync(join(sourceDir, 'readme-images'), { force: true, recursive: true });
114
  const readmePath = join(sourceDir, 'README.md');
115
- writeFileSync(readmePath, rewriteSpaceReadmeImageSources(readFileSync(readmePath, 'utf8'), repoSlug, localSha), 'utf8');
 
 
 
 
116
  return sourceDir;
117
  }
118
 
@@ -137,6 +142,10 @@ export function isHfUploadExistingSpacePolicyError(error) {
137
  );
138
  }
139
 
 
 
 
 
140
  export function buildUploadArgs({ sourceDir, localSha, repoSlug, deletePaths = [] }) {
141
  if (!repoSlug?.trim()) throw new Error('REPO_SLUG is required for deploy metadata.');
142
  const args = [
@@ -166,9 +175,10 @@ function readLocalGitFiles() {
166
  return new Set(output.split('\0').filter(isSpaceDeployPath));
167
  }
168
 
169
- function readRemoteFilePaths() {
170
- const info = readSpaceInfo();
171
- return (info.siblings || []).map((sibling) => sibling.rfilename).filter((filename) => typeof filename === 'string' && filename.length > 0);
 
172
  }
173
 
174
  export function findRemoteDeletePaths(localFiles, remoteFiles) {
@@ -190,15 +200,22 @@ export function buildDeployMarker(localSha, createdAt = new Date(), deployId = r
190
 
191
  export function assertDeployMarkerMatches(marker, expectedMarker) {
192
  if (!marker || typeof marker !== 'object') throw new Error('deploy marker response was not an object.');
193
- if (marker?.schema_version !== expectedMarker.schema_version) throw new Error('deploy marker schema_version mismatch.');
 
194
  if (marker.local_sha !== expectedMarker.local_sha) {
195
- throw new Error(`deploy marker local_sha mismatch: expected ${expectedMarker.local_sha}, received ${marker.local_sha || 'missing'}.`);
 
 
196
  }
197
  if (marker.created_at !== expectedMarker.created_at) {
198
- throw new Error(`deploy marker created_at mismatch: expected ${expectedMarker.created_at}, received ${marker.created_at || 'missing'}.`);
 
 
199
  }
200
  if (marker.deploy_id !== expectedMarker.deploy_id) {
201
- throw new Error(`deploy marker deploy_id mismatch: expected ${expectedMarker.deploy_id}, received ${marker.deploy_id || 'missing'}.`);
 
 
202
  }
203
  return marker;
204
  }
@@ -239,7 +256,15 @@ function readLocalGitFilesWithDeployMarker() {
239
 
240
  function uploadSourceTree(sourceDir, deployMarker, repoSlug) {
241
  writeDeployMarker(sourceDir, deployMarker);
242
- const deletePaths = findRemoteDeletePaths(readLocalGitFilesWithDeployMarker(), readRemoteFilePaths());
 
 
 
 
 
 
 
 
243
  try {
244
  const output = runText(
245
  'hf',
@@ -411,7 +436,9 @@ async function main() {
411
 
412
  if (isMainModule(import.meta.url, process.argv[1])) {
413
  main().catch((error) => {
414
- console.error(JSON.stringify({ ok: false, error: error instanceof Error ? error.message : String(error) }, null, 2));
 
 
415
  process.exit(1);
416
  });
417
  }
 
1
  #!/usr/bin/env node
2
+ import { fetchJsonWithTimeout, parseJsonPayload, runCommandStrict } from './command-center-utils.mjs';
3
+ import { assertKnownOptions, HF_SPACE_ID, HF_SPACE_URL, isMainModule } from './hf-space-doctor-utils.mjs';
4
  import { spawnSync } from 'node:child_process';
5
  import { randomUUID } from 'node:crypto';
6
  import { cpSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
 
8
  import { join } from 'node:path';
9
  import { setTimeout as delay } from 'node:timers/promises';
10
 
 
 
 
11
  const STATUS_POLL_ATTEMPTS = 40;
12
  const STATUS_POLL_INTERVAL_MS = 10_000;
13
  const PUBLIC_ENDPOINT_TIMEOUT_MS = 10_000;
 
32
  console.log(`Usage:
33
  npm run deploy:hf-space
34
 
35
+ Deploys the current clean git HEAD to ${HF_SPACE_ID}.
36
 
37
+ Existing Docker Spaces use an authenticated Git push. Other Space types try the
38
+ official hf CLI first. The script waits for the Space to run the new commit and
39
+ performs read-only public endpoint checks.`);
40
  }
41
 
42
  function runText(command, args, options = {}) {
 
92
  const normalized = String(filePath || '')
93
  .replaceAll('\\', '/')
94
  .replace(/^\.\//, '');
95
+ return (
96
+ normalized.length > 0 && !SPACE_DEPLOY_EXCLUDED_PATH_PREFIXES.some((prefix) => normalized.startsWith(prefix))
97
+ );
98
  }
99
 
100
  export function rewriteSpaceReadmeImageSources(readme, repoSlug, localSha) {
 
113
  runText('tar', ['-x', '-C', sourceDir], { input: archive });
114
  rmSync(join(sourceDir, 'readme-images'), { force: true, recursive: true });
115
  const readmePath = join(sourceDir, 'README.md');
116
+ writeFileSync(
117
+ readmePath,
118
+ rewriteSpaceReadmeImageSources(readFileSync(readmePath, 'utf8'), repoSlug, localSha),
119
+ 'utf8'
120
+ );
121
  return sourceDir;
122
  }
123
 
 
142
  );
143
  }
144
 
145
+ export function shouldUseGitPushForSpace(spaceInfo) {
146
+ return spaceInfo?.sdk === 'docker';
147
+ }
148
+
149
  export function buildUploadArgs({ sourceDir, localSha, repoSlug, deletePaths = [] }) {
150
  if (!repoSlug?.trim()) throw new Error('REPO_SLUG is required for deploy metadata.');
151
  const args = [
 
175
  return new Set(output.split('\0').filter(isSpaceDeployPath));
176
  }
177
 
178
+ function readRemoteFilePaths(info) {
179
+ return (info.siblings || [])
180
+ .map((sibling) => sibling.rfilename)
181
+ .filter((filename) => typeof filename === 'string' && filename.length > 0);
182
  }
183
 
184
  export function findRemoteDeletePaths(localFiles, remoteFiles) {
 
200
 
201
  export function assertDeployMarkerMatches(marker, expectedMarker) {
202
  if (!marker || typeof marker !== 'object') throw new Error('deploy marker response was not an object.');
203
+ if (marker?.schema_version !== expectedMarker.schema_version)
204
+ throw new Error('deploy marker schema_version mismatch.');
205
  if (marker.local_sha !== expectedMarker.local_sha) {
206
+ throw new Error(
207
+ `deploy marker local_sha mismatch: expected ${expectedMarker.local_sha}, received ${marker.local_sha || 'missing'}.`
208
+ );
209
  }
210
  if (marker.created_at !== expectedMarker.created_at) {
211
+ throw new Error(
212
+ `deploy marker created_at mismatch: expected ${expectedMarker.created_at}, received ${marker.created_at || 'missing'}.`
213
+ );
214
  }
215
  if (marker.deploy_id !== expectedMarker.deploy_id) {
216
+ throw new Error(
217
+ `deploy marker deploy_id mismatch: expected ${expectedMarker.deploy_id}, received ${marker.deploy_id || 'missing'}.`
218
+ );
219
  }
220
  return marker;
221
  }
 
256
 
257
  function uploadSourceTree(sourceDir, deployMarker, repoSlug) {
258
  writeDeployMarker(sourceDir, deployMarker);
259
+ const remoteSpace = readSpaceInfo();
260
+ const deletePaths = findRemoteDeletePaths(readLocalGitFilesWithDeployMarker(), readRemoteFilePaths(remoteSpace));
261
+ if (shouldUseGitPushForSpace(remoteSpace)) {
262
+ console.log('Deploying the existing Docker Space via an authenticated Git push.');
263
+ return {
264
+ spaceCommitSha: uploadSourceTreeWithGit(sourceDir, deployMarker),
265
+ transport: 'git_push_existing_docker_space'
266
+ };
267
+ }
268
  try {
269
  const output = runText(
270
  'hf',
 
436
 
437
  if (isMainModule(import.meta.url, process.argv[1])) {
438
  main().catch((error) => {
439
+ console.error(
440
+ JSON.stringify({ ok: false, error: error instanceof Error ? error.message : String(error) }, null, 2)
441
+ );
442
  process.exit(1);
443
  });
444
  }
scripts/deploy-hf-space.test.mjs CHANGED
@@ -1,6 +1,3 @@
1
- import assert from 'node:assert/strict';
2
- import { describe, it } from 'node:test';
3
-
4
  import {
5
  GIT_ARCHIVE_MAX_BUFFER_BYTES,
6
  assertDeployMarkerMatches,
@@ -8,6 +5,7 @@ import {
8
  buildDeployMarkerRouteSource,
9
  isSpaceDeployPath,
10
  isHfUploadExistingSpacePolicyError,
 
11
  buildUploadArgs,
12
  extractUploadCommitSha,
13
  findRemoteDeletePaths,
@@ -15,6 +13,8 @@ import {
15
  rewriteSpaceReadmeImageSources,
16
  waitForRunning
17
  } from './deploy-hf-space.mjs';
 
 
18
 
19
  describe('HF Space deploy script', () => {
20
  it('recognizes the existing Docker Space create-policy error for the Git deployment fallback', () => {
@@ -25,8 +25,24 @@ describe('HF Space deploy script', () => {
25
  ].join('\n');
26
 
27
  assert.equal(isHfUploadExistingSpacePolicyError(policyError), true);
28
- assert.equal(isHfUploadExistingSpacePolicyError("Client error '402 Payment Required' for url 'https://huggingface.co/api/models/create'"), false);
29
- assert.equal(isHfUploadExistingSpacePolicyError("Client error '401 Unauthorized' for url 'https://huggingface.co/api/repos/create'"), false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  });
31
 
32
  it('extracts the Space commit SHA from hf upload JSON output', () => {
@@ -41,7 +57,10 @@ describe('HF Space deploy script', () => {
41
  });
42
 
43
  it('rejects upload output without a Space commit URL', () => {
44
- assert.throws(() => extractUploadCommitSha('{"url":"https://huggingface.co/spaces/misonL/demo"}'), /commit SHA or commit URL/);
 
 
 
45
  });
46
 
47
  it('extracts the Space commit SHA from direct hf upload JSON fields', () => {
@@ -80,7 +99,10 @@ describe('HF Space deploy script', () => {
80
  args[args.indexOf('--commit-description') + 1],
81
  'Source: MisonL/gpt-image-playground-customer@bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
82
  );
83
- assert.equal(args.some((arg) => arg.includes('\n')), false);
 
 
 
84
  });
85
 
86
  it('uses a provided repository slug in upload commit metadata', () => {
@@ -90,12 +112,21 @@ describe('HF Space deploy script', () => {
90
  repoSlug: 'owner/repo'
91
  });
92
 
93
- assert.equal(args[args.indexOf('--commit-description') + 1], 'Source: owner/repo@eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee');
 
 
 
94
  });
95
 
96
  it('parses GitHub repository slugs from common origin URL formats', () => {
97
- assert.equal(parseRepositorySlug('https://github.com/MisonL/gpt-image-playground-customer.git'), 'MisonL/gpt-image-playground-customer');
98
- assert.equal(parseRepositorySlug('git@github.com:MisonL/gpt-image-playground-customer.git'), 'MisonL/gpt-image-playground-customer');
 
 
 
 
 
 
99
  assert.throws(() => parseRepositorySlug('not-a-github-url'), /Set REPO_SLUG=owner\/repo/);
100
  });
101
 
@@ -179,8 +210,14 @@ describe('HF Space deploy script', () => {
179
  });
180
 
181
  it('builds a unique deploy marker id when none is provided', () => {
182
- const first = buildDeployMarker('3333333333333333333333333333333333333333', new Date('2026-06-20T10:00:00.000Z'));
183
- const second = buildDeployMarker('3333333333333333333333333333333333333333', new Date('2026-06-20T10:00:00.000Z'));
 
 
 
 
 
 
184
 
185
  assert.match(first.deploy_id, /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
186
  assert.notEqual(first.deploy_id, second.deploy_id);
@@ -283,12 +320,10 @@ describe('HF Space deploy script', () => {
283
 
284
  it('keeps the generated deploy markers from being deleted on upload', () => {
285
  assert.deepEqual(
286
- findRemoteDeletePaths(new Set(['README.md', 'public/hf-space-deploy-marker.json', 'src/app/api/deploy-marker/route.ts']), [
287
- 'README.md',
288
- 'public/hf-space-deploy-marker.json',
289
- 'src/app/api/deploy-marker/route.ts',
290
- 'old.md'
291
- ]),
292
  ['old.md']
293
  );
294
  });
 
 
 
 
1
  import {
2
  GIT_ARCHIVE_MAX_BUFFER_BYTES,
3
  assertDeployMarkerMatches,
 
5
  buildDeployMarkerRouteSource,
6
  isSpaceDeployPath,
7
  isHfUploadExistingSpacePolicyError,
8
+ shouldUseGitPushForSpace,
9
  buildUploadArgs,
10
  extractUploadCommitSha,
11
  findRemoteDeletePaths,
 
13
  rewriteSpaceReadmeImageSources,
14
  waitForRunning
15
  } from './deploy-hf-space.mjs';
16
+ import assert from 'node:assert/strict';
17
+ import { describe, it } from 'node:test';
18
 
19
  describe('HF Space deploy script', () => {
20
  it('recognizes the existing Docker Space create-policy error for the Git deployment fallback', () => {
 
25
  ].join('\n');
26
 
27
  assert.equal(isHfUploadExistingSpacePolicyError(policyError), true);
28
+ assert.equal(
29
+ isHfUploadExistingSpacePolicyError(
30
+ "Client error '402 Payment Required' for url 'https://huggingface.co/api/models/create'"
31
+ ),
32
+ false
33
+ );
34
+ assert.equal(
35
+ isHfUploadExistingSpacePolicyError(
36
+ "Client error '401 Unauthorized' for url 'https://huggingface.co/api/repos/create'"
37
+ ),
38
+ false
39
+ );
40
+ });
41
+
42
+ it('uses Git directly for an existing Docker Space', () => {
43
+ assert.equal(shouldUseGitPushForSpace({ sdk: 'docker' }), true);
44
+ assert.equal(shouldUseGitPushForSpace({ sdk: 'gradio' }), false);
45
+ assert.equal(shouldUseGitPushForSpace({}), false);
46
  });
47
 
48
  it('extracts the Space commit SHA from hf upload JSON output', () => {
 
57
  });
58
 
59
  it('rejects upload output without a Space commit URL', () => {
60
+ assert.throws(
61
+ () => extractUploadCommitSha('{"url":"https://huggingface.co/spaces/misonL/demo"}'),
62
+ /commit SHA or commit URL/
63
+ );
64
  });
65
 
66
  it('extracts the Space commit SHA from direct hf upload JSON fields', () => {
 
99
  args[args.indexOf('--commit-description') + 1],
100
  'Source: MisonL/gpt-image-playground-customer@bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
101
  );
102
+ assert.equal(
103
+ args.some((arg) => arg.includes('\n')),
104
+ false
105
+ );
106
  });
107
 
108
  it('uses a provided repository slug in upload commit metadata', () => {
 
112
  repoSlug: 'owner/repo'
113
  });
114
 
115
+ assert.equal(
116
+ args[args.indexOf('--commit-description') + 1],
117
+ 'Source: owner/repo@eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
118
+ );
119
  });
120
 
121
  it('parses GitHub repository slugs from common origin URL formats', () => {
122
+ assert.equal(
123
+ parseRepositorySlug('https://github.com/MisonL/gpt-image-playground-customer.git'),
124
+ 'MisonL/gpt-image-playground-customer'
125
+ );
126
+ assert.equal(
127
+ parseRepositorySlug('git@github.com:MisonL/gpt-image-playground-customer.git'),
128
+ 'MisonL/gpt-image-playground-customer'
129
+ );
130
  assert.throws(() => parseRepositorySlug('not-a-github-url'), /Set REPO_SLUG=owner\/repo/);
131
  });
132
 
 
210
  });
211
 
212
  it('builds a unique deploy marker id when none is provided', () => {
213
+ const first = buildDeployMarker(
214
+ '3333333333333333333333333333333333333333',
215
+ new Date('2026-06-20T10:00:00.000Z')
216
+ );
217
+ const second = buildDeployMarker(
218
+ '3333333333333333333333333333333333333333',
219
+ new Date('2026-06-20T10:00:00.000Z')
220
+ );
221
 
222
  assert.match(first.deploy_id, /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
223
  assert.notEqual(first.deploy_id, second.deploy_id);
 
320
 
321
  it('keeps the generated deploy markers from being deleted on upload', () => {
322
  assert.deepEqual(
323
+ findRemoteDeletePaths(
324
+ new Set(['README.md', 'public/hf-space-deploy-marker.json', 'src/app/api/deploy-marker/route.ts']),
325
+ ['README.md', 'public/hf-space-deploy-marker.json', 'src/app/api/deploy-marker/route.ts', 'old.md']
326
+ ),
 
 
327
  ['old.md']
328
  );
329
  });
src/app/api/deploy-marker/route.ts CHANGED
@@ -1,6 +1,6 @@
1
  import { NextResponse } from 'next/server';
2
 
3
- const deployMarker = {"schema_version":1,"local_sha":"444b7abc99f5bfa03760ceefb2beb0d790f0aba9","created_at":"2026-07-20T08:14:53.507Z","deploy_id":"a25ce1ac-a4d0-4982-bc6d-796a92ff195f"} as const;
4
 
5
  export const dynamic = 'force-dynamic';
6
 
 
1
  import { NextResponse } from 'next/server';
2
 
3
+ const deployMarker = {"schema_version":1,"local_sha":"36a4274a16b48a50059a1a47e8711352c09c479a","created_at":"2026-07-20T08:55:43.290Z","deploy_id":"f19889c7-48c8-4069-8dd0-cae4ae827d8f"} as const;
4
 
5
  export const dynamic = 'force-dynamic';
6