@pippit-dev/cli 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/checksums.txt CHANGED
@@ -1,6 +1,6 @@
1
- 3e95e8bbd667579fa1feddd4c58e583d70003f0f179d7249135b883a612165e5 pippit-tool-cli-0.0.27-darwin-amd64.tar.gz
2
- 15671a5880feff8a67bd0c8042ab7e2a77d1ea7c81ed6625427bdd472d925c6a pippit-tool-cli-0.0.27-darwin-arm64.tar.gz
3
- aef2fc4896d2c8966f681a82e5bd624b9ec9f0382e23dd05776f014cbb65473d pippit-tool-cli-0.0.27-linux-amd64.tar.gz
4
- 5b01a760298c22a6fd42661f212f9f1d1e822e84d1feb87307c36590f795515a pippit-tool-cli-0.0.27-linux-arm64.tar.gz
5
- 18315d247bb409f594d11e64cb2292ffbf48504d73290011f5c5a2ba319f93df pippit-tool-cli-0.0.27-windows-amd64.zip
6
- 31284208bc244d9d48066c8e7086bf40e167209fff106ea6462c9638cbd6efef pippit-tool-cli-0.0.27-windows-arm64.zip
1
+ 91f6452453768a4af724e7f478c1d5834b117dfd57545eb28f79838bcefee72c pippit-tool-cli-0.0.28-darwin-amd64.tar.gz
2
+ 72784be227214d5821793241ec19c0d41227cbcf1bf10b8d8a3675b8a1093219 pippit-tool-cli-0.0.28-darwin-arm64.tar.gz
3
+ 1b7197befef5930b91816a1021a7ab66b9f3d95c0cbd5b0ba5fea20c1a7a1173 pippit-tool-cli-0.0.28-linux-amd64.tar.gz
4
+ 2452ba5f9dc74b516af47e4e4620cfcc247ffe0b2d46a847681910442535f62b pippit-tool-cli-0.0.28-linux-arm64.tar.gz
5
+ bdb744c4e3cc57774c97148665ba99a6952fd4a1293902728e16a655544b20dc pippit-tool-cli-0.0.28-windows-amd64.zip
6
+ 52e660a8b334067fa056021dcf68f1bb13a0385f6792a45b93277463cd583200 pippit-tool-cli-0.0.28-windows-arm64.zip
@@ -11,6 +11,7 @@ import (
11
11
  "path/filepath"
12
12
  "runtime"
13
13
  "strings"
14
+ "sync"
14
15
  "time"
15
16
 
16
17
  "github.com/Pippit-dev/pippit-cli/internal/version"
@@ -23,6 +24,7 @@ const (
23
24
  defaultTelemetryBaseURL = "https://xyq.jianying.com"
24
25
  telemetryPath = "/api/biz/v1/skill/report_telemetry"
25
26
  telemetryAuthHeader = "Bearer pippit-cli-skill-telemetry"
27
+ telemetryWaitTimeout = time.Second
26
28
  )
27
29
 
28
30
  var legacyGlobalSkills = []string{
@@ -35,7 +37,7 @@ var telemetrySkillNames = []string{
35
37
  "xyq-short-drama-skill",
36
38
  }
37
39
 
38
- var telemetryHTTPClient = &http.Client{Timeout: 2 * time.Second}
40
+ var telemetryHTTPClient = &http.Client{Timeout: telemetryWaitTimeout}
39
41
 
40
42
  // NewCommand builds the update command.
41
43
  func NewCommand(stdout, stderr io.Writer) *cobra.Command {
@@ -137,6 +139,7 @@ func reportBundledSkillTelemetry(event string, source string, stderr io.Writer)
137
139
  if os.Getenv("PIPPIT_CLI_DISABLE_TELEMETRY") == "1" {
138
140
  return
139
141
  }
142
+ var wg sync.WaitGroup
140
143
  for _, skillName := range telemetrySkillNames {
141
144
  payload := telemetryPayload{
142
145
  Event: event,
@@ -146,12 +149,23 @@ func reportBundledSkillTelemetry(event string, source string, stderr io.Writer)
146
149
  Platform: runtime.GOOS,
147
150
  Arch: runtime.GOARCH,
148
151
  }
152
+ wg.Add(1)
149
153
  go func(payload telemetryPayload) {
154
+ defer wg.Done()
150
155
  if err := reportSkillTelemetry(payload); err != nil && os.Getenv("PIPPIT_CLI_DEBUG_TELEMETRY") == "1" {
151
156
  fmt.Fprintf(stderr, "[pippit-tool-cli] telemetry failed: %v\n", err)
152
157
  }
153
158
  }(payload)
154
159
  }
160
+ done := make(chan struct{})
161
+ go func() {
162
+ wg.Wait()
163
+ close(done)
164
+ }()
165
+ select {
166
+ case <-done:
167
+ case <-time.After(telemetryWaitTimeout):
168
+ }
155
169
  }
156
170
 
157
171
  func reportSkillTelemetry(payload telemetryPayload) error {
@@ -10,6 +10,7 @@ import (
10
10
  "runtime"
11
11
  "strings"
12
12
  "testing"
13
+ "time"
13
14
  )
14
15
 
15
16
  func TestInstallSkillsInstallsAllBundledSkills(t *testing.T) {
@@ -117,6 +118,47 @@ func TestReportSkillTelemetry(t *testing.T) {
117
118
  }
118
119
  }
119
120
 
121
+ func TestReportBundledSkillTelemetryWaitsBriefly(t *testing.T) {
122
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
123
+ time.Sleep(2 * time.Second)
124
+ _, _ = w.Write([]byte(`{"ret":"0","errmsg":""}`))
125
+ }))
126
+ defer server.Close()
127
+
128
+ t.Setenv("PIPPIT_CLI_TELEMETRY_BASE_URL", server.URL)
129
+ start := time.Now()
130
+ reportBundledSkillTelemetry("update", "cli_update", &bytes.Buffer{})
131
+ if elapsed := time.Since(start); elapsed > 1500*time.Millisecond {
132
+ t.Fatalf("reportBundledSkillTelemetry() blocked for %v, want <= 1.5s", elapsed)
133
+ }
134
+ }
135
+
136
+ func TestReportBundledSkillTelemetryReportsBothSkills(t *testing.T) {
137
+ skillNames := make(chan string, len(telemetrySkillNames))
138
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
139
+ var payload telemetryPayload
140
+ if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
141
+ t.Fatalf("decode request body: %v", err)
142
+ }
143
+ skillNames <- payload.SkillName
144
+ _, _ = w.Write([]byte(`{"ret":"0","errmsg":""}`))
145
+ }))
146
+ defer server.Close()
147
+
148
+ t.Setenv("PIPPIT_CLI_TELEMETRY_BASE_URL", server.URL)
149
+ reportBundledSkillTelemetry("update", "cli_update", &bytes.Buffer{})
150
+
151
+ got := map[string]bool{}
152
+ for i := 0; i < len(telemetrySkillNames); i++ {
153
+ got[<-skillNames] = true
154
+ }
155
+ for _, skillName := range telemetrySkillNames {
156
+ if !got[skillName] {
157
+ t.Fatalf("missing telemetry for %s, got %#v", skillName, got)
158
+ }
159
+ }
160
+ }
161
+
120
162
  func TestTelemetryBaseURL(t *testing.T) {
121
163
  t.Setenv("PIPPIT_CLI_TELEMETRY_BASE_URL", " ")
122
164
  t.Setenv("XYQ_OPENAPI_BASE", "https://example.com///")
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@pippit-dev/cli",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "Pippit CLI",
5
5
  "bin": {
6
6
  "pippit-tool-cli": "scripts/run.js"
7
7
  },
8
8
  "scripts": {
9
9
  "postinstall": "node scripts/install.js",
10
- "test": "node scripts/version-check.test.js && node scripts/skills.test.js && go test ./... && go vet ./..."
10
+ "test": "node scripts/version-check.test.js && node scripts/skills.test.js && node scripts/install-wizard.test.js && go test ./... && go vet ./..."
11
11
  },
12
12
  "os": [
13
13
  "darwin",
@@ -6,7 +6,15 @@ const { isWindows, run, runSilent } = require("./platform");
6
6
  const { DEFAULT_PKG, installGlobalPackageSkills } = require("./skills");
7
7
  const { reportBundledSkillTelemetry } = require("./telemetry");
8
8
 
9
- const PKG = process.env.PIPPIT_CLI_INSTALL_PACKAGE || DEFAULT_PKG;
9
+ const VERSION = require("../package.json").version.replace(/-.*$/, "");
10
+
11
+ function defaultInstallPackage() {
12
+ return `${DEFAULT_PKG}@${VERSION}`;
13
+ }
14
+
15
+ function installPackage() {
16
+ return process.env.PIPPIT_CLI_INSTALL_PACKAGE || defaultInstallPackage();
17
+ }
10
18
 
11
19
  function getGloballyInstalledVersion() {
12
20
  try {
@@ -38,13 +46,14 @@ function whichPippitToolCli() {
38
46
  }
39
47
 
40
48
  function main() {
49
+ const pkg = installPackage();
41
50
  const installed = getGloballyInstalledVersion();
42
51
  if (installed) {
43
- console.log(`Updating global pippit-tool-cli (${installed}) via ${PKG}...`);
52
+ console.log(`Updating global pippit-tool-cli (${installed}) via ${pkg}...`);
44
53
  } else {
45
- console.log(`Installing ${PKG} globally...`);
54
+ console.log(`Installing ${pkg} globally...`);
46
55
  }
47
- run("npm", ["install", "-g", PKG], {
56
+ run("npm", ["install", "-g", pkg], {
48
57
  timeout: 120000,
49
58
  env: { ...process.env, PIPPIT_CLI_SKIP_SKILLS: "1" },
50
59
  });
@@ -57,7 +66,7 @@ function main() {
57
66
  throw err;
58
67
  }
59
68
  console.log("Existing global package does not contain skills; reinstalling...");
60
- run("npm", ["install", "-g", PKG], { timeout: 120000 });
69
+ run("npm", ["install", "-g", pkg], { timeout: 120000 });
61
70
  installGlobalPackageSkills(DEFAULT_PKG);
62
71
  }
63
72
 
@@ -73,4 +82,12 @@ function main() {
73
82
  console.log("Try: pippit-tool-cli short-drama +submit-run --message \"写一个短剧开头\"");
74
83
  }
75
84
 
76
- main();
85
+ if (require.main === module) {
86
+ main();
87
+ }
88
+
89
+ module.exports = {
90
+ defaultInstallPackage,
91
+ installPackage,
92
+ main,
93
+ };
package/scripts/run.js CHANGED
@@ -38,7 +38,7 @@ if (process.platform === "win32" && fs.existsSync(oldBin)) {
38
38
  // Match the lark-cli install entry: `npx @pippit-dev/cli@latest install`
39
39
  // should run the JS setup flow before the native binary exists.
40
40
  if (args[0] === "install") {
41
- require("./install-wizard.js");
41
+ require("./install-wizard.js").main();
42
42
  } else {
43
43
  maybeWarnNewVersion(args);
44
44