Skip to content

fix(resources): 兼容 Windows/Linux 的打包资源目录 - #319

Merged
helsome merged 1 commit into
helsome:mainfrom
huyengiang101086-spec:fix/packaged-resource-directory
Oct 13, 2026
Merged

helsome merged 1 commit into
helsome:mainfrom
huyengiang101086-spec:fix/packaged-resource-directory

Conversation

@huyengiang101086-spec

Copy link
Copy Markdown
Contributor

改动说明

Windows / Linux 的 Electron 资源目录是小写 resources,原定位器只认 Resources,导致打包模式错误回退到源码路径,技能目录、Pi cwd 和扩展入口随之错误。

改为比较最后一个路径段的完整名称(忽略大小写),保持 FINAGENT_PACKAGED=1 门禁。回归覆盖两种资源目录名、技能及两个扩展的打包路径、开发环境门禁,并拒绝 NotResources 这样的后缀误匹配。

关联 Issue

Closes #318

测试报告

环境

  • Bun:1.4.2 (744846f84)
  • OS:Windows 11 (10.0.26200)
  • Electron:39.8.9
  • 基线:main a6da0059ecafe4426c9a841ec59215655ebcabd1

实际执行命令与结果

bun test packages/shared/src/resources/resource-locator.test.ts
→ 原生产代码 + 新回归:5 pass / 2 fail
→ 修复后:7 pass / 0 fail,19 expect

bun test packages/shared --isolate
→ 1122 pass / 0 fail,4375 expect,100 files

bun run typecheck
→ core / i18n / shared / ui / electron 全部 exit 0

git diff --check
→ exit 0

真实 Electron main-process smoke:用 Bun 将基线/修复后的定位器分别打成 CJS,然后以 Electron 运行以下脚本。使用真实 process.resourcesPath,只模拟 Folio 根据 app.isPackaged 设置的 flag。

bun build resource-locator.ts --target=node --format=cjs --outfile resource-locator.cjs
electron resource-smoke.cjs <resource-locator.cjs 的绝对路径>
→ 基线:exit 1,false !== true
→ 修复后:exit 0,Electron 39.8.9,resourcesPath 末段为 resources
resource-smoke.cjs(可复现)
const assert = require('node:assert/strict');
const { basename, join } = require('node:path');
const { app } = require('electron');
const locator = require(process.argv[2]);
app.whenReady().then(() => {
  try {
    delete process.env.FINAGENT_PACKAGED;
    assert.equal(locator.isPackaged(), false);
    process.env.FINAGENT_PACKAGED = '1';
    assert.equal(basename(process.resourcesPath), 'resources');
    assert.equal(locator.isPackaged(), true);
    assert.equal(locator.getRuntimeRoot(), process.resourcesPath);
    assert.equal(locator.getSkillsDir(), join(process.resourcesPath, 'skills'));
    assert.equal(locator.getPiExtensionEntry(), join(process.resourcesPath, 'extensions', 'finagent', 'index.js'));
    assert.equal(locator.getLangSmithExtensionEntry(), join(process.resourcesPath, 'extensions', 'langsmith', 'index.js'));
    assert.equal(locator.getPiCwd(), process.resourcesPath);
    console.log(JSON.stringify({ status: 'pass', electron: process.versions.electron, resourcesPath: process.resourcesPath }));
    app.exit(0);
  } catch (error) {
    console.error(error.message);
    app.exit(1);
  }
});

已知失败 / Baseline

最终检查无失败。未运行完整安装包 E2E,未验证实际扩展加载。macOS / Linux 路径仅由单元测试及 electron-builder 源码核对,真实 Electron smoke 在 Windows 执行。

  • 已提供实际测试命令与 pass/fail 结果
  • 已说明测试环境
  • 核心改动已有 focused test / smoke 验证

UI 截图

  • 本 PR 无可见 UI 变化(内部资源路径判定,无需截图)

Scope / 后续

仅改资源定位器及其测试,不修改打包配置、IPC、扩展实现或 UI。独立基于上游 main,与 PR #317 无提交或文件依赖。Codex 在用户授权下准备改动与验证。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目录名完整匹配且忽略大小写的修复正确,仍保留 FINAGENT_PACKAGED 门禁,没有扩大到新的资源加载机制。已核对 #318 认领与测试:作者提供 Windows/Bun/Electron 版本、focused 7/0、shared 1122/0、全部 typecheck,并附真实 Electron main-process smoke 的脚本和红→绿结果;对本次路径判定足够,不要求安装包全链路或截图。当前没有 head 的 PR Actions run,批准依据为代码审查及上述作者报告,不声称 CI 已通过。

@helsome
helsome merged commit d19e8b7 into helsome:main Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(resources): Windows/Linux 打包资源目录被误判为开发模式

2 participants