From 89879a9f7d1e6c287a771f80f90685d2c07df270 Mon Sep 17 00:00:00 2001 From: Faradayff Date: Fri, 17 Jul 2026 11:04:22 +0200 Subject: [PATCH 1/3] Enhance Guardar button extraction with comprehensive regex matching for robustness --- internal/clients/myteam2go.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/clients/myteam2go.go b/internal/clients/myteam2go.go index 735c761..e1be89d 100644 --- a/internal/clients/myteam2go.go +++ b/internal/clients/myteam2go.go @@ -396,15 +396,26 @@ func (c *MyTeam2GoClocker) submitWorkAssistance(ctx context.Context, action work } // ── Extract Guardar button name ─────────────────────────────────────────── - btnRegex := regexp.MustCompile(`name="(workAssistanceForm:j_idt\d+)"[^>]*>]*>Guardar`) - btnMatches := btnRegex.FindStringSubmatch(menuHtml) - if len(btnMatches) < 2 { - btnMatches = btnRegex.FindStringSubmatch(html) - if len(btnMatches) < 2 { - return fmt.Errorf("could not find Guardar button in workAssistanceForm") + btnName := "" + // Match with possible nested tags + btnRegexText := regexp.MustCompile(`name="(workAssistanceForm:[^"]+)"[^>]*>(?:<[^>]+>)*\s*Guardar\s*<`) + // Match + btnRegexVal := regexp.MustCompile(`name="(workAssistanceForm:[^"]+)"[^>]*value="Guardar"`) + + for _, htmlSource := range []string{menuHtml, html} { + if btnMatches := btnRegexText.FindStringSubmatch(htmlSource); len(btnMatches) >= 2 { + btnName = btnMatches[1] + break } + if btnMatches := btnRegexVal.FindStringSubmatch(htmlSource); len(btnMatches) >= 2 { + btnName = btnMatches[1] + break + } + } + + if btnName == "" { + return fmt.Errorf("could not find Guardar button in workAssistanceForm") } - btnName := btnMatches[1] // ── Extract option value ────────────────────────────────────────────────── optRegex := regexp.MustCompile(`value="(\d+)"[^>]*>` + regexp.QuoteMeta(action.optionLabel) + `<`) From 133d30b3f6ff27f9ddaf3e38e9c2ded509652c38 Mon Sep 17 00:00:00 2001 From: Faradayff Date: Fri, 17 Jul 2026 11:10:55 +0200 Subject: [PATCH 2/3] Add `FridayTimes` configuration to schedule test setup --- internal/core/schedule_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/core/schedule_test.go b/internal/core/schedule_test.go index d56c38e..6849991 100644 --- a/internal/core/schedule_test.go +++ b/internal/core/schedule_test.go @@ -134,6 +134,7 @@ func TestRandomizeHours(t *testing.T) { cfg := &config.Config{ ClockIn: config.ClockTime{Time: clockInTime}, ClockOut: config.ClockTime{Time: clockOutTime}, + FridayTimes: []config.ClockTime{{Time: clockInTime}, {Time: clockOutTime}}, Lunchtime: &config.ClockTime{Time: lunchTime}, MinTimeToLunch: 30, MaxTimeToLunch: 60, From 724dd8057fa28ce851701ce3bce6e25bbaa1cfcd Mon Sep 17 00:00:00 2001 From: Faradayff Date: Fri, 17 Jul 2026 15:36:44 +0200 Subject: [PATCH 3/3] Remove redundant debug log statements in myteam2go client --- internal/clients/myteam2go.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/clients/myteam2go.go b/internal/clients/myteam2go.go index e1be89d..7fbf0a9 100644 --- a/internal/clients/myteam2go.go +++ b/internal/clients/myteam2go.go @@ -460,7 +460,6 @@ func (c *MyTeam2GoClocker) submitWorkAssistance(ctx context.Context, action work } changeBytes, _ := io.ReadAll(changeResp.Body) changeHtml := string(changeBytes) - slog.Debug("🌐 Change event response", "body", changeHtml) if err := changeResp.Body.Close(); err != nil { slog.Warn("⚠️ submitWorkAssistance: failed to close change response body", "error", err) } @@ -515,7 +514,6 @@ func (c *MyTeam2GoClocker) submitWorkAssistance(ctx context.Context, action work respBody, _ := io.ReadAll(postResp.Body) respStr := string(respBody) - slog.Debug("🌐 Guardar response", "action", action.logVerb, "body", respStr) if strings.Contains(respStr, "No se ha podido efectuar") { return fmt.Errorf("%s rejected by server: no se ha podido efectuar el registro", action.logVerb)