Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .gf/tests/gfcode/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (gfcode ...) 内置扩展单元测试

`tests/gfcode/` 验证 `.gf/gfcode/` 内置扩展库统一导出 `extension` 工厂的加载与注册行为。
`tests/gfcode/` 验证 `.gf/gfcode/` 单文件内置扩展库导出 `extension` 工厂的加载与注册行为。
多文件扩展位于各 domain 的 `gfcode/<name>/index.scm`(如 `review/gfcode/code-review/`),
其单元测试随 domain 放在 `<domain>/tests/gfcode/<name>/index/`。

从仓库根目录运行:

Expand All @@ -9,6 +11,11 @@ gf test .gf/tests/gfcode
```

- `tps/extension-test.scm` - TPS 扩展:事件钩子、usage 累加、格式化输出与通知回退
- `code-review/extension-test.scm` - code-review 扩展:flags / commands / validator / flow / prompt injector 注册
- `simplify/extension-test.scm` - simplify 扩展:flags / commands / validator / flow 注册
- `web-search/extension-test.scm` - web-search 扩展:web_search 工具注册与默认启用

多文件扩展测试:

```bash
gf test review/tests/gfcode
gf test simplify/tests/gfcode
gf test web-search/tests/gfcode
```
11 changes: 0 additions & 11 deletions .gf/tests/gfcode/code-review/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions .gf/tests/gfcode/simplify/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions .gf/tests/gfcode/web-search/README.md

This file was deleted.

164 changes: 85 additions & 79 deletions .github/workflows/test-plugins-debian.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,85 @@
name: Test built-in plugins on Debian trixie

# 内置插件共用一个 CI job,依次运行各自测试。
# 安装最新的 Goldfish,与主测试 workflow 保持一致。

on:
workflow_dispatch:
push:
branches: [main]
paths:
- '.gf/gfcode/**'
- '.gf/tests/**'
- 'ai/**'
- 'agent/**'
- 'code/**'
- 'review/**'
- 'simplify/**'
- 'tests/**'
- 'web-search/**'
- 'gfproject.json'
- '.github/workflows/test-plugins-debian.yml'
pull_request:
paths:
- '.gf/gfcode/**'
- '.gf/tests/**'
- 'ai/**'
- 'agent/**'
- 'code/**'
- 'review/**'
- 'simplify/**'
- 'tests/**'
- 'web-search/**'
- 'gfproject.json'
- '.github/workflows/test-plugins-debian.yml'

env:
DEBIAN_FRONTEND: noninteractive

jobs:
plugins:
container: debian:trixie
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Install dependencies
run: |
apt-get update
apt-get install -y git curl ca-certificates python3

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: git add safe directory
run: git config --global --add safe.directory '*'

- name: Install Goldfish (latest)
run: |
TAG=$(curl -fsSL -H "User-Agent: gfcode-ci" \
-H "Authorization: Bearer ${{ github.token }}" \
https://api.github.com/repos/MoganLab/goldfish/releases/latest \
| python3 -c "import sys, json; print(json.load(sys.stdin)['tag_name'])")
echo "Latest goldfish release: $TAG"
curl -fsSL -o /tmp/goldfish.deb \
"https://github.com/MoganLab/goldfish/releases/download/$TAG/goldfish-scheme-x86_64-$TAG.deb"
apt-get install -y /tmp/goldfish.deb
gf version

- name: Test tps project extension
run: gf test .gf/tests/gfcode

- name: Test review plugin
run: gf test review/tests/liii

- name: Test simplify plugin
run: gf test simplify/tests/liii

- name: Test web-search plugin
run: gf test web-search/tests/liii
name: Test built-in plugins on Debian trixie

# 内置插件共用一个 CI job,依次运行各自测试。
# 安装最新的 Goldfish,与主测试 workflow 保持一致。

on:
workflow_dispatch:
push:
branches: [main]
paths:
- '.gf/gfcode/**'
- '.gf/tests/**'
- 'ai/**'
- 'agent/**'
- 'code/**'
- 'review/**'
- 'simplify/**'
- 'tests/**'
- 'web-search/**'
- 'gfproject.json'
- '.github/workflows/test-plugins-debian.yml'
pull_request:
paths:
- '.gf/gfcode/**'
- '.gf/tests/**'
- 'ai/**'
- 'agent/**'
- 'code/**'
- 'review/**'
- 'simplify/**'
- 'tests/**'
- 'web-search/**'
- 'gfproject.json'
- '.github/workflows/test-plugins-debian.yml'

env:
DEBIAN_FRONTEND: noninteractive

jobs:
plugins:
container: debian:trixie
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Install dependencies
run: |
apt-get update
apt-get install -y git curl ca-certificates python3

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: git add safe directory
run: git config --global --add safe.directory '*'

- name: Install Goldfish (latest)
run: |
TAG=$(curl -fsSL -H "User-Agent: gfcode-ci" \
-H "Authorization: Bearer ${{ github.token }}" \
https://api.github.com/repos/MoganLab/goldfish/releases/latest \
| python3 -c "import sys, json; print(json.load(sys.stdin)['tag_name'])")
echo "Latest goldfish release: $TAG"
curl -fsSL -o /tmp/goldfish.deb \
"https://github.com/MoganLab/goldfish/releases/download/$TAG/goldfish-scheme-x86_64-$TAG.deb"
apt-get install -y /tmp/goldfish.deb
gf version

- name: Test tps project extension
run: gf test .gf/tests/gfcode

- name: Test review plugin
run: |
gf test review/tests/liii
gf test review/tests/gfcode

- name: Test simplify plugin
run: |
gf test simplify/tests/liii
gf test simplify/tests/gfcode

- name: Test web-search plugin
run: |
gf test web-search/tests/liii
gf test web-search/tests/gfcode
60 changes: 53 additions & 7 deletions code/liii/pi/code/core/extensions/discovery.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,33 @@
) ;export
(begin

;; 源码树内的扩展候选目录:除 .gf/gfcode 外,各 domain 根下的
;; gfcode/ 目录(如 review/gfcode、simplify/gfcode、web-search/gfcode)
;; 也参与内置发现;同一 gfcode 目录只收录一次。
(define (%source-tree-extension-candidates)
(let loop
((roots *load-path*) (acc '()))
(if (null? roots)
(reverse acc)
(let ((root (path (car roots))))
(let* ((root (path (car roots)))
(gfcode-dir (path-join root "gfcode"))
(next-acc (if (path-dir? gfcode-dir) (cons gfcode-dir acc) acc))
) ;
(loop (cdr roots)
(if (and (string=? (path-name root) ".gf") (path-dir? (path-join root "gfcode")))
(cons (path-join root "gfcode") acc)
acc
) ;if
(let dedup
((rest next-acc) (seen '()) (out '()))
(if (null? rest)
(reverse out)
(let ((key (%normalize-path (car rest))))
(dedup (cdr rest)
(cons key seen)
(if (member key seen) out (cons (car rest) out))
) ;dedup
) ;let
) ;if
) ;let
) ;loop
) ;let
) ;let*
) ;if
) ;let
) ;define
Expand Down Expand Up @@ -231,7 +245,39 @@
) ;user-entries
(project-entries (pi-scan-extension-dir (path-join (path cwd-dir) ".gf" "gfcode"))
) ;project-entries
(builtin-entries (if include-builtin? (pi-scan-extension-dir builtin-dir) '()))
;; 内置层 = 默认内置目录 + 源码树各 domain 的 gfcode/ 目录;
;; 按归一化路径去重,同名扩展由 %merge-extension-layer 仲裁。
;; PI_BUILTIN_EXTENSIONS_DIR 显式指定时只用该目录,保证隔离。
(builtin-dirs
(let dedup
((rest
(cond ((not include-builtin?) '())
((get-environment-variable "PI_BUILTIN_EXTENSIONS_DIR")
=>
(lambda (dir) (list dir))
) ;
(else (append (list builtin-dir)
(%source-tree-extension-candidates)
(list (path ".gf/gfcode") (path "../.gf/gfcode"))
) ;append
) ;else
) ;cond
) ;rest
(seen '())
(out '())
) ;
(if (null? rest)
(reverse out)
(let ((key (%normalize-path (car rest))))
(dedup (cdr rest)
(cons key seen)
(if (member key seen) out (cons (car rest) out))
) ;dedup
) ;let
) ;if
) ;let
) ;builtin-dirs
(builtin-entries (append-map pi-scan-extension-dir builtin-dirs))
(project-gfcode-dir (path-join (path cwd-dir) ".gf" "gfcode"))
;; 内置扩展与项目扩展统一位于 .gf/gfcode:cwd 的 .gf/gfcode 即内置目录
;; 时只扫描一次,避免同名副本重复注册;用户级 ~/.gf/gfcode 作为中间层。
Expand Down
17 changes: 14 additions & 3 deletions code/liii/pi/code/core/extensions/loader.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,27 @@
(let* ((path-str (if (path? entry) (path->string entry) entry))
(p (path path-str))
(filename (path-name p))
(name
(stem
(if (string-ends? filename ".scm")
(substring filename 0 (- (string-length filename) 4))
filename
) ;if
) ;stem
(parent-dir (path-parent p))
;; index.scm 位于扩展子目录内:库名为 (gfcode <dir> index),
;; root 取 gfcode 目录本身;单文件入口仍为 (gfcode <stem>)。
(index? (string=? stem "index"))
(name
(if index?
(list 'gfcode (string->symbol (path-name parent-dir)) 'index)
(list 'gfcode (string->symbol stem))
) ;if
) ;name
(root (path-parent (path-parent p)))
(root (if index? (path-parent (path-parent parent-dir)) (path-parent parent-dir))
) ;root
) ;
(list (cons 'type 'library)
(cons 'name (list 'gfcode (string->symbol name)))
(cons 'name name)
(cons 'root (path->string (path-resolve root)))
(cons 'path (path->string (path-resolve p)))
) ;list
Expand Down
6 changes: 3 additions & 3 deletions code/tests/liii/pi/code/config/resolve-active-tools-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
(args-empty (parse-pi-args '()))
(args-override (parse-pi-args '("--tools" "read,bash")))
(api-ws (make-extension-api))
(_ (pi-load-extension (if (file-exists? ".gf/gfcode/web-search.scm")
".gf/gfcode/web-search.scm"
"../.gf/gfcode/web-search.scm"
(_ (pi-load-extension (if (file-exists? "web-search/gfcode/web-search/index.scm")
"web-search/gfcode/web-search/index.scm"
"../web-search/gfcode/web-search/index.scm"
) ;if
api-ws
) ;pi-load-extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,37 @@
) ;check-false
) ;let

;; 4. 源码树 domain 根下的 gfcode/<name>/index.scm 作为内置扩展被发现,
;; 库名为 (gfcode <name> index)。
(let* ((root (path-join (path-temp-dir) "pi-discover-domain-builtin"))
(ext-dir (path-join root "gfcode" "domain-ext"))
(file (path-join ext-dir "index.scm"))
(saved-load-path *load-path*)
) ;
(path-mkdir ext-dir :parents #t :exist-ok #t)
(path-write-text file
(string-append "(define-library (gfcode domain-ext index)\n"
" (import (scheme base)) (export extension)\n"
" (begin (define (extension api) \"domain-ext\"))))\n"
) ;string-append
) ;path-write-text
(set! *load-path* (cons (path->string root) *load-path*))
(let* ((entries (pi-discover-extensions :cwd (path->string (path-temp-dir))))
(found
(find (lambda (entry) (equal? (%entry-name entry) '(gfcode domain-ext
index)))
entries
) ;find
) ;found
) ;
(check-true (and found #t))
(check (cdr (assq 'path found))
=>
(string-replace (path->string (path-resolve file)) "\\" "/")
) ;check
) ;let*
(set! *load-path* saved-load-path)
(rmtree (path->string root) #t)
) ;let*

(check-report)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
;; Licensed under the MIT License
;;

(define-library (gfcode code-review)
(define-library (gfcode code-review index)
(import (scheme base)
(liii string)
(liii pi code core extensions)
Expand Down
Loading
Loading