mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 11:02:26 +00:00
fix(docs): continue partial i18n batches after file errors
This commit is contained in:
@@ -212,7 +212,7 @@ export async function selectFoundryDeployment(
|
||||
})),
|
||||
});
|
||||
const selected =
|
||||
supported.find((deployment) => deployment.name === selectedDeploymentName) ?? supported[0]!;
|
||||
supported.find((deployment) => deployment.name === selectedDeploymentName) ?? supported[0];
|
||||
return { selected, supported };
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ func runDocSequential(ctx context.Context, ordered []string, translator docsTran
|
||||
start := time.Now()
|
||||
skip, outputPath, err := processFileDoc(ctx, translator, docsRoot, file, srcLang, tgtLang, overwrite)
|
||||
if err != nil {
|
||||
if shouldStopDocRun(ctx, allowPartial) {
|
||||
if shouldStopDocRun(ctx, err, allowPartial) {
|
||||
return processed, skipped, outputs, err
|
||||
}
|
||||
if firstErr == nil {
|
||||
@@ -259,7 +259,7 @@ func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tg
|
||||
skipped: skip,
|
||||
err: err,
|
||||
}
|
||||
if err != nil && shouldStopDocRun(ctx, allowPartial) {
|
||||
if err != nil && shouldStopDocRun(ctx, err, allowPartial) {
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
@@ -306,11 +306,11 @@ func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tg
|
||||
return processed, skipped, outputs, firstErr
|
||||
}
|
||||
|
||||
func shouldStopDocRun(ctx context.Context, allowPartial bool) bool {
|
||||
func shouldStopDocRun(ctx context.Context, err error, allowPartial bool) bool {
|
||||
if !allowPartial {
|
||||
return true
|
||||
}
|
||||
return ctx.Err() != nil
|
||||
return ctx.Err() != nil || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
|
||||
}
|
||||
|
||||
func runSegmentSequential(ctx context.Context, ordered []string, translator docsTranslator, tm *TranslationMemory, docsRoot, srcLang, tgtLang string) (int, []string, error) {
|
||||
|
||||
@@ -126,6 +126,24 @@ func (cancelAwareTranslator) TranslateRaw(ctx context.Context, text, _, _ string
|
||||
|
||||
func (cancelAwareTranslator) Close() {}
|
||||
|
||||
type contextErrorTranslator struct{}
|
||||
|
||||
func (contextErrorTranslator) Translate(_ context.Context, text, _, _ string) (string, error) {
|
||||
if strings.Contains(text, "CANCEL") {
|
||||
return "", context.Canceled
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
|
||||
func (contextErrorTranslator) TranslateRaw(_ context.Context, text, _, _ string) (string, error) {
|
||||
if strings.Contains(text, "CANCEL") {
|
||||
return "", context.Canceled
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
|
||||
func (contextErrorTranslator) Close() {}
|
||||
|
||||
type cancelAfterFirstDocTranslator struct {
|
||||
cancel context.CancelFunc
|
||||
calls int
|
||||
@@ -376,6 +394,42 @@ func TestRunDocsI18NAllowPartialReturnsCancellationAfterPartialSuccess(t *testin
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunDocsI18NAllowPartialStopsAfterContextError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
docsRoot := t.TempDir()
|
||||
writeFile(t, filepath.Join(docsRoot, ".i18n", "glossary.zh-CN.json"), "[]")
|
||||
writeFile(t, filepath.Join(docsRoot, "docs.json"), `{"redirects":[]}`)
|
||||
firstPath := filepath.Join(docsRoot, "aaa-first.md")
|
||||
cancelPath := filepath.Join(docsRoot, "bbb-cancel.md")
|
||||
laterPath := filepath.Join(docsRoot, "zzz-later.md")
|
||||
writeFile(t, firstPath, "# Gateway\n")
|
||||
writeFile(t, cancelPath, "# CANCEL\n")
|
||||
writeFile(t, laterPath, "# Gateway\n")
|
||||
|
||||
err := runDocsI18N(context.Background(), runConfig{
|
||||
targetLang: "zh-CN",
|
||||
sourceLang: "en",
|
||||
docsRoot: docsRoot,
|
||||
mode: "doc",
|
||||
thinking: "high",
|
||||
overwrite: true,
|
||||
allowPartial: true,
|
||||
parallel: 1,
|
||||
}, []string{firstPath, cancelPath, laterPath}, func(_, _ string, _ []GlossaryEntry, _ string) (docsTranslator, error) {
|
||||
return contextErrorTranslator{}, nil
|
||||
})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("expected cancellation error to remain terminal, got %v", err)
|
||||
}
|
||||
if got := mustReadFile(t, filepath.Join(docsRoot, "zh-CN", "aaa-first.md")); !strings.Contains(got, "# Gateway") {
|
||||
t.Fatalf("expected first output to be written before cancellation, got:\n%s", got)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(docsRoot, "zh-CN", "zzz-later.md")); err == nil {
|
||||
t.Fatal("did not expect later output to be written after context error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunDocsI18NRewritesLineTitleFromExactGlossaryWithoutModel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user